|
-
May 10th, 2005, 04:24 AM
#1
Thread Starter
Lively Member
simple cade
hi,
how can i get the output like : 0, 1, 1, 2, 3, 5, 8, 13, 21 ..........
please help.
-
May 10th, 2005, 04:31 AM
#2
Member
Re: simple cade
Please explain in detail, as the question is really vague.
-
May 10th, 2005, 04:41 AM
#3
Thread Starter
Lively Member
Re: simple cade
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
-
May 10th, 2005, 05:00 AM
#4
Re: simple cade
Code:
Console.Writeline("0, 1, 1, 2, 3, 5, 8, 13, 21 ..........");
Take my wife...
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() + ",");
}
}
-
May 10th, 2005, 11:59 AM
#5
Thread Starter
Lively Member
Re: simple cade
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#
-
May 10th, 2005, 08:32 PM
#6
Re: simple cade
The Fibonacci sequence, you mean, and you'd like to access the nth element of the array?
-
May 10th, 2005, 08:33 PM
#7
Re: simple cade
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];
}
}
-
May 11th, 2005, 11:03 AM
#8
Junior Member
Re: simple cade
public static int Fibonacci(int n, int k)
That's some slick code. Nice job.
Dan
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|