c 语言求斐波那契数列
时间: 2023-06-21 12:17:43 浏览: 183
python 求斐波那契数列(示例)
好的,下面是 C 语言实现的斐波那契数列:
```c
#include <stdio.h>
int main() {
int n, t1 = 0, t2 = 1, nextTerm;
printf("请输入要输出的斐波那契数列的项数:");
scanf("%d", &n);
printf("斐波那契数列:");
for (int i = 1; i <= n; ++i) {
printf("%d ", t1);
nextTerm = t1 + t2;
t1 = t2;
t2 = nextTerm;
}
return 0;
}
```
这段代码会根据输入的项数输出相应的斐波那契数列。
阅读全文