hi,
how can i get the output like : 0, 1, 1, 2, 3, 5, 8, 13, 21 ..........
please help. :confused:
Printable View
hi,
how can i get the output like : 0, 1, 1, 2, 3, 5, 8, 13, 21 ..........
please help. :confused:
Please explain in detail, as the question is really vague. :confused:
hi,
i m very new in C#. i want to display the output in : 0 , 1 , 1 ,2 , 3, 5, 8 , 13, 21 .....
for example:
n=0, output=0
n=1, output = 1
n=2, output = 1
n=3, output = 2
n=4 output = 3
n=5, output = 5
n=6, output = 8
n=7 output = 13
Take my wife...Code:Console.Writeline("0, 1, 1, 2, 3, 5, 8, 13, 21 ..........");
Please.
ba dom
Seriously what is the information how is it stored?
Code:int[] arr = {0,1,1,2,3,4,6,8};
for(int i=0;i<arr.Length;i++){
Console.WriteLine("n="+i.ToString() + " output=" + arr[i].ToString());
}
//or
for(int i=0;i<arr.Length;i++){
if(i==arr.Length-1){
Console.WriteLine(i.ToString());
}
else{
Console.Write(i.ToString() + ",");
}
}
hi,
if i have 2 textbox, 1 is for keying the number and another 1 is for the display.
for example, i key in 6 in textbox1, the 8 will display on textbox2. if i key in 100 in textbox1, i want the result will display in textbox2.
and my number format is : 0, 1, 1, 2, 3, 5, 8, 13, 21, 34..... that means the 1st number + 2nd number = 3rd number
how can i write it in C#
The Fibonacci sequence, you mean, and you'd like to access the nth element of the array?
Like this:
PHP Code:public static int Fibonacci(int n, int k)
{
if (n < k - 1)
return 0;
else if (n == k - 1)
return 1;
else
{
int[] f = new int[n + 1];
for (int i = 0; i < k - 1; ++i)
f[i] = 0;
f[k - 1] = 1;
for (int i = k; i <= n; ++i)
{
int sum = 0;
for (int j = 1; j <= k; ++j)
sum += f[i - j];
f[i] = sum;
}
return f[n];
}
}
That's some slick code. Nice job.Quote:
public static int Fibonacci(int n, int k)
Dan