C# program to print the Fibonacci series using recursion
Program.cs
Console.WriteLine("———————————————————————————————————————————");
Console.WriteLine("Program to print the Fibonacci series");
Console.WriteLine("———————————————————————————————————————————");
Console.Write("How many elements you want to print ");
int n = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < n; i++)
{
    int F = Fibonacci(i);
    Console.WriteLine(F);
}
Console.WriteLine("———————————————————————————————————————————");

static int Fibonacci(int n)
{
    if ((n == 0) || (n == 1))
    {
        return n;
    }
    else
    {
        return Fibonacci(n - 1) + Fibonacci(n - 2);
    }
}
Output
kodingwindow@kw:~/csharp$ dotnet run
———————————————————————————————————————————
Program to print the Fibonacci series
———————————————————————————————————————————
How many elements you want to print 15
0
1
1
2
3
5
8
13
21
34
55
89
144
233
377
———————————————————————————————————————————
kodingwindow@kw:~/csharp$ 
Advertisement