C#递归求斐波那契数列


using System;
namespace HxRuntech
{
    public class T1
    {
        static void Main()
        {
            int num = 10;

            int x = Fibonacci(num);
            Console.WriteLine(x);
        }
        /// <summary>
        /// fn(1) = 0
        /// fn(2) = 1
        /// fn(3) = fn(1)+fn(2)
        /// fn(n) = fn(n-2)+fn(n-1)
        /// </summary>
        /// <param name="n"></param>
        /// <returns></returns>
       static int Fibonacci(int n)
        {
            if(n == 1)
            {
                return 0;
            }else if(n ==2)
            {
                return 1;
            }
            else
            {
                return Fibonacci(n - 1) + Fibonacci(n-2);
            }
        }
    }
}