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 Tech Blog - https://www.code-sample.com/
My Books - Book 1 and Book 2

Fibonacci Series using Recursion and Loop in ASP.Net C# Fibonacci Series using Recursion and Loop in ASP.Net C# Reviewed by Anil Singh on 1:22 PM Rating: (5)
www.code-sample.com/. Powered by Blogger.
^