Friday, March 26, 2010

How to generate Fibonacci series in c#

open a console application project in c# language in your editor and just paste the following code in your class's brackets -

static void Main(string[] args)
{
int previous = -1; int next = 1;
int position;
Console.WriteLine("Enter the position");
position = int.Parse(Console.ReadLine());
for (int i = 0; i < position; i++)
{
int sum = next + previous; previous = next;
next = sum;
Console.WriteLine(next);
}
Console.ReadLine();
}

Output is -

3 comments:

  1. wrong, position 9 is 34. you are not showing position 9, position 8 = 21.

    ReplyDelete
    Replies
    1. shut-up man,,, do it your-self, dis program is fine...

      Delete