递归算法

一列数的规则如下: 1、1、2、3、5、8、13、21、34...... 求第30位数是多少, 用递归算法实现

namespace rabbit

{

             class Program

           {

               static void Main(string[] args)

                {

                     Console.WriteLine("请输入个正数:");

                     int I= int.Parse(Console.ReadLine());

                     Console.WriteLine("第{0}个数字是{1}", I, Fn(I));

                }

              static int Fn(int n)

                {

                    if ( n == 1 || n == 2 )

                      {

                          return 1;

                      }

                    else

                      {

                          return Fn(n - 1) + Fn(n - 2);

                      }

                }

    }

}

原文地址:https://www.cnblogs.com/dongwenhua/p/9000991.html