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