Monday 28 January 2013



// Write a program to print the fibonacci series

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

namespace fibo
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, i, pre = 0;
            int next = 1;
            Console.WriteLine("Enter the value of n:  ");
            n = Convert.ToInt32(Console.ReadLine());
            for (i = 2; i <= n; i++)
            {
                int a = pre + next;
                Console.WriteLine(" " + a);
                pre = next;
                next = a;
            }
            Console.ReadKey();
            }
        }
    }

No comments:

Post a Comment