python ruby-programming-language Smalltalk Vue.js Knockoutjs TypeScript JavaScript, OOPs JavaScript Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 4 Angular 2 AngularJs 1.x NodeJs Perl Programming R Programming RequireJs Rust Programming Backbonejs closure programming language go-programming-language kotlin-programming-language
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

Hi there! Welcome to my blog. My name is Anil Singh. I'm a author of this blog. For more detail about me, kindly refer to this link..
My Blogs - http://code-sample.com and http://code-sample.xyz
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like
www.code-sample.com/. Powered by Blogger.
ASK Questions