面试题

笔试题:

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

代码实现:

 1 using System;
 2 
 3 namespace DataStrut
 4 {
 5     class Program
 6     {
 7         static void Main(string[] args)
 8         {
 9 
10             for(int i=0;i<=30;i++)
11             {
12                 int value = Foo(i);
13                 Console.WriteLine(value);
14             }
15             Console.ReadKey();
16         }
17 
18         public static int Foo(int m)
19         {
20             if (m <= 0)
21                 return 0;
22             else if (m > 0 && m <= 2)
23                 return 1;
24             else
25                 return Foo(m - 1) + Foo(m - 2);
26         }
27     }
28 }
运行结果:
 
 
原文地址:https://www.cnblogs.com/luoshengjie/p/10369297.html