Thursday, 15 October 2015

Fibonacci Series using for loop in C#

using System;
class Program
{
    public static void Main()
    {
        int a = 0, b = 1;
        Console.WriteLine("Please Enter your Target?");
        int target = int.Parse(Console.ReadLine());
        Console.Write(a+"\t");
        for (; b < target;)
        {
            Console.Write(b+"\t");
            b = a + b;
            a = b - a;
        }
        Console.WriteLine("\n");
    }
}

No comments:

Post a Comment