Social Icons

Wednesday, 12 February 2014

Program to generate Fibonacci series up to given number

using System;
namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, b = 1, s = 0, a = 0;
            Console.Write("\n Enter number at which you want to print series : ");
            n = int.Parse(Console.ReadLine());
            Console.Write("\n The series is : ");
            while (n != 0)
            {
                s = s + a;
                a = b;
                b = s;
                n--;
                Console.Write("    " + s);
            }
            Console.ReadLine();
        }
    }
}


                                                         Output

No comments:

Post a Comment