Tuesday, May 3, 2016

WAP to print Fibonacci numbers below 100

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication12
{
    class class1
    {
        public static int Fib(int n)
        {
            int a = 0;
            int b = 1;
      
            for (int i = 0; i < n; i++)
            {
                int temp = a;
                a = b;
                b = temp + b;
            }
            return a;
        }

        static void Main()
        {
            for (int i = 0; i < 12; i++)
            {
                Console.WriteLine(Fib(i));
                Console.ReadKey();
            }
        }
    }
}
Output :

No comments:

Post a Comment