用C语言的循环语句求解斐波那契数列的前40项
时间: 2023-11-18 14:57:55 浏览: 76
斐波那契数用for循环和if语句编写 1个脚本数列按照顺序排列
```c
#include <stdio.h>
int main() {
int n = 40;
int fib1 = 0, fib2 = 1;
printf("%d %d ", fib1, fib2);
for(int i = 3; i <= n; i++) {
int fib3 = fib1 + fib2;
printf("%d ", fib3);
fib1 = fib2;
fib2 = fib3;
}
return 0;
}
```
阅读全文