标签:pre fibonacci std include ret print cci nbsp int
全部代码
1 #include <stdio.h>
2
3 int Fibonacci(int n)
4 {
5 if(1==n || 2==n)
6 {
7 return 1;
8 }
9
10 return Fibonacci(n-1) + Fibonacci(n-2);
11 }
12
13 int Fibonacci2(int n)
14 {
15 int sum = 0;
16 int f1 = 1;
17 int f2 = 1;
18 int i;
19
20 if(1==n || 2==n)
21 {
22 return 1;
23 }
24
25 for(i=3; i<=n; ++i)
26 {
27 sum = f1+f2;
28 f1 = f2;
29 f2 = sum;
30 }
31
32 return sum;
33 }
34
35 int main(void)
36 {
37 printf("%d\n", Fibonacci(8));
38 printf("%d\n", Fibonacci2(8));
39
40 return 0;
41 }
标签:pre fibonacci std include ret print cci nbsp int
原文地址:http://www.cnblogs.com/chen-cai/p/7859214.html