斐波那契数组数组法

 1 /* 斐波那契数组数组法 */
 2 
 3 #include<stdio.h>
 4 #include<stdlib.h>
 5 
 6 // 1  1  2  3  5  8 
 7 
 8 int get(int i)// 递归
 9 {
10     if (i==1 || i==2)
11     {
12         return 1;
13     }
14     else
15     {
16         return get(i-1)+get(i-2);
17     }
18 }
19 
20 void main()
21 {
22     printf("%d",get(40));
23     
24     int a[40];
25     a[0] = 1;
26     a[1] = 1;
27     for (int i=2;i<40;i++)// 循环快于递归
28     {
29         a[i] = a[i-1]+a[i-2];
30     }
31 
32     printf("%d",a[39]);
33 
34 
35 
36     system("pause");
37 }

 

posted on 2015-06-20 16:16  Dragon-wuxl  阅读(410)  评论(0)    收藏  举报

导航