- Course
- Recursion
- Calculate Fibonacci series numbers

# Calculate Fibonacci series numbers

Last updated:
8/23/2020
⁃
Difficulty:
Intermediate

Create a C# program that uses recursion to calculate a number in the series of Fibonacci.

In the Fibonacci series, the series begins with the numbers 0 and 1, from these, each term is the sum of the previous two.

#### Input

13

#### Output

233

#### Solution

using System;
public class CalculateFibonacci
{
public static void Main(string[] args)
{
int n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(Fibonacci(n));
Console.ReadLine();
}
public static int Fibonacci(int n)
{
if ((n == 1) || (n == 2))
{
return 1;
}
else
{
return Fibonacci(n - 1) + Fibonacci(n - 2);
}
}
}