用数组求Fibonacci7数列前20个数,要求每行输出5个

2024-10-30 16:09:41
推荐回答(1个)
回答1:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

#include
int main()
{
int fibonacci[32], i, j;
fibonacci[1] = fibonacci[2] = 1;
for (i = 3;i <= 20;i++)
fibonacci[i] = fibonacci[i - 1] + fibonacci[i - 2];
for (i = 0;i < 4;i++)
{
printf("%d", fibonacci[i * 5 + 1]);
for (j = 2;j <= 5;j++)
printf(" %d", fibonacci[i * 5 + j]);
printf("\n");
}
return 0;
}