Thursday, 15 October 2015

Fibonacci series in using while loop in C#

using System;
class Program
{
    public static void Main()
    {
        int Num1,Num2;
        Num1 = 0;
        Num2 = 1;
        Console.WriteLine("Enter your target?");
        int target = int.Parse(Console.ReadLine());
        Console.WriteLine(Num1);
        while (Num2 < target)
        {
            Console.WriteLine(Num2);
            Num2 = Num1 + Num2;
            Num1 = Num2 - Num1;
        }
    }
}

No comments:

Post a Comment