例28:斐波那契数列

哎,这个斐波那契数列,正着写反着写写了N遍了,但是其实也还没烦,有时候感觉这个挺有意思的。代码如下:

 1 #include<stdio.h>
 2 #include<stdlib.h> 
 3 
 4 int Test(int n)
 5 {
 6      int pArray[n+1];
 7      for(int i = 1;i<n+1;i++)
 8      {
 9              if(i == 1 || i == 2)
10              {
11                   pArray[i] = 1;
12              }
13              else 
14              {
15                   pArray[i] = pArray[i-1] + pArray[i-2];
16              }
17              printf("%10Id	",pArray[i]);
18              if(i%3 == 0)printf("
");
19      }
20 }
21 
22 int main()
23 {
24     int n;
25     while(~scanf("%d",&n) && n)
26     {
27         Test(n);
28     }
29     return 0;
30 }
原文地址:https://www.cnblogs.com/FWFC/p/6298117.html