Sunday, 5 February 2012

Fibonacci Numbers


Program to print Fibonacci Numbers below 100.

using System;
class myclass
{
    static void Main()
    {
        int fn = 0;
        int sn = 1;
        int tn = 1;

        Console.WriteLine(fn);
        Console.WriteLine(sn);
        while (true)
        {

            tn = fn + sn;
            if (tn >= 100)
            {
                break;
            }
            Console.WriteLine(tn);
            fn = sn;
            sn = tn;

        }
        Console.Read();

    }
}

Output

0
1
1
2
3
5
8
13
21
34
55
89

No comments:

Post a Comment