首页 > 代码库 > 递归算法

递归算法

 static void Main(string[] args)
        {
            Console.WriteLine(foo(30));
            Console.ReadKey();
           
        }
        public static int foo(int i)
        {
            if (i <= 0)
            {
                return 0;
            }
            else if (i >= 0 && i <= 2)
            {
                return 1;
            }
            else
                return foo(i - 1) + foo(i - 2);
        }

递归算法