fibonacci series in c# using recursion

Fibonacci Series using Recursion and Loop in ASP.Net C#

Hello everyone, I am going to share the code sample for the recursion fibonacci series using c# with console application as given below.


public class FibonacciSeries
{
    static void Main(string[] ax)
    {
        Console.WriteLine("Enter the number.");
        int number = Convert.ToInt32(Console.ReadLine());

        //USING LOOP FOR GET FIBONACCI SERIES.
        FibonicciAlgo(number);         

        //USING RECURCIVE METHOD FOR GET FIBONACCI SERIES.
        Fibonacci_Recurcive(0, 1, 1, number);
    }

    /// <summary>
    /// USING LOOP FOR GET FIBONACCI SERIES.
    /// </summary>
    private static void FibonicciAlgo(int number)
    {
        int a = -1;
        int b = 1;
        for (int i = 0; i < number; i++)
        {
            int c = b + a;
            a = b;
            b = c;
            Console.Write("{0} ", b);
        }
        Console.ReadLine();
    }

    /// <summary>
    /// USING RECURCIVE METHOD FOR GET FIBONACCI SERIES.
    /// </summary>
    private static void Fibonacci_Recurcive(int a, int b, int counter, int number)
    {
        if (counter <= number)
        {
            Console.Write("{0} ", a);
            Fibonacci_Recurcive(b, a + b, counter + 1, number);
        }
        Console.ReadLine();
    }

}

The live output


ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..
My Blogs - https://code-sample.com and https://code-sample.xyz
My Book1 - BEST SELLING ANGULAR BOOK (INCLUDING ALL VERSIONS 2, 4, 5, 6, 7)
My Book2 - ANGULAR 2 INTERVIEW QUESTIONS BOOK - Both Books are Available on WorldWide.

www.code-sample.com/. Powered by Blogger.