Source:
int Fibonacci(int n) //use long or double if n>46
{
	if (n < 2) return n;
    return Fibonacci(n - 1) + Fibonacci(n - 2);
}
Sample Usage:
using System;

namespace NullDoc
{
    class Program
    {
        static void Main(string[] args)
        {
            int number = 100;
            do
            {
                Console.Write("Please enter a valid number (1-47):");
            } while (!((int.TryParse(Console.ReadLine(), out number) && number <= 47)));

            Console.WriteLine("Fibonacci of {0} is {1}", number, Program.Fibonacci(number));            
        }

        private static int Fibonacci(int n) 
        {
            if (n < 2) return n;
            return Fibonacci(n - 1) + Fibonacci(n - 2);
        }
    }
}

In mathematics, the Fibonacci numbers or Fibonacci series or Fibonacci sequence are the numbers in the following integer sequence:0, 1, 1, 2, 3, 5, 8, 13... By definition, the first two numbers in the Fibonacci sequence are 0 and 1, and each subsequent number is the sum of the previous two. In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation Fn = F(n-1) + F(n-2) with seed values. Source: http://en.wikipedia.org/wiki/Fibonacci_number

DotNetHokage 6 years ago