#include <stdio.h>
int main(){
int n;
int a[999] = {0};
int b[999] = {0};
int c[999] = {0};
int i,count = 0;
scanf ("%d",&n);
if (n < 1||n > 46){
printf ("Invalid.");
}else{
a[0] = 1,b[0] = 1;
for (i = 0;i < n;i++){
c[i+1] = a[i] + b[i];
a[i+1] = b[i];
b[i+1] = c[i+1];
printf ("%11d",a[i]);
count++;
if(count % 5 ==0){
printf ("\n");
}
}
}
return 0;
}
7-29 利用数组计算斐波那契数列 (15 分)
最新推荐文章于 2023-08-29 15:02:22 发布