用数组求Fibonacci7数列前20个数,要求每行输出5个
1个回答
2016-06-19
展开全部
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <stdio.h>
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;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <stdio.h>
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;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询