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

来源:互联网 发布:淘宝真假混卖店铺名单 编辑:程序博客网 时间:2024/06/05 06:44

 

 using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace ConsoleApplication1

{

   class Program

   {

       static void Main(string[] args)

       {

           Console.WriteLine(Foo(20));

           Console.ReadLine();

       }

       public staticint Foo(int i)

       {

           if (i <= 0)

           {

               return 0;

           }

           else if (i >= 1 && i <= 2)

           {

               return 1;

           }

           else

           {

               return Foo(i - 1) + Foo(i - 2);

           }

       }

   }

}

原创粉丝点击