Pages

Monday, April 1, 2013

How to write C# program for fibonacci series


Below is the code to generate the Fibonacci series


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

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            int first = 0, second = 1, third, number, i;
            Console.WriteLine("Enter the value for number");
            number = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("The fibonacci series is:");
            Console.WriteLine(first);
            Console.WriteLine(second);
            for (i = 2; i < number; i++)
            {
                third = first + second;
                first = second;
                second = third;
                Console.WriteLine(third);
            }
            Console.ReadKey();

        }
    }
}

No comments:

Post a Comment