In this C# program, we will learn how to write a program to print the Fibonacci series using recursion.
In mathematics, the Fibonacci numbers, commonly denoted Fn form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. That is,
F0=0 and F1=1
And
Fn=Fn-1 + Fn-2
Example of Fibonacci Series is 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 and so on.
Here is the code of the program to print Fibonacci series using recursion.:
using System;
namespace TutorialsrackPrograms
{
class Program
{
//Program to print a Fibonacci Series Using Recursion
static void Main(string[] args)
{
Console.Write("Enter The Number: ");
int number = Convert.ToInt32(Console.ReadLine());
Console.Write("Fibonacci Series Using Recursion: ");
Fibonacci(0, 1, 1, number);
Console.Read();
}
public static void Fibonacci(int a, int b, int counter, int number)
{
Console.Write(a + " ");
if (counter < number) Fibonacci(b, a + b, counter + 1, number);
}
}
}
Enter The Number: 10
Fibonacci Series Using Recursion: 0 1 1 2 3 5 8 13 21 34
Comments