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

 1 public class MainClass  
 2 {  
 3 public static void Main()  
 4 {  
 5 Console.WriteLine(Foo(30));  
 6 }  
 7 public static int Foo(int i)  
 8 {  
 9 if (i <= 0)  
10 return 0;  
11 else if(i > 0 && i <= 2)  
12 return 1;  
13 else return Foo(i -1) + Foo(i - 2);  
14 }  
15 }  

猜你喜欢

转载自www.cnblogs.com/myBlogOu/p/9940059.html