c语言 编程斐波那契数列前40项(要求每行输出4项)
时间: 2023-05-31 13:07:40 浏览: 104
Sure, here's the code for generating the first 40 terms of the Fibonacci sequence using C language:
```c
#include <stdio.h>
int main() {
int n, first = 0, second = 1, next;
printf("The first 40 terms of the Fibonacci sequence are:\n");
for(n = 0; n < 40; n++) {
if(n % 4 == 0 && n > 0)
printf("\n"); // start a new line every 4 terms
if(n <= 1)
next = n;
else {
next = first + second;
first = second;
second = next;
}
printf("%d\t", next); // output the next term
}
return 0;
}
```
I hope that helps! Let me know if you have any other questions.
阅读全文