21 October 2013

How to generate the Fabonacci Series in C#.Net


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = -1;
            int b = 1;
            int x;
            Console.WriteLine("Enter the x value =");
            x = int.Parse(Console.ReadLine());
            for (int i = 0; i < x; i++)
            {
                int sum = b + a;
                a = b;
                b = sum;
                Console.WriteLine(sum);


            }
            Console.ReadLine();
        }
    }
}







No comments:

Post a Comment