用c语言编写斐波那契数列的循环嵌套
时间: 2023-12-10 13:06:27 浏览: 145
杨辉三角形c语言编写fo循环
5星 · 资源好评率100%
以下是使用C语言编写斐波那契数列的循环嵌套的代码:
```c
#include <stdio.h>
int main() {
int n, i;
long long t1 = 0, t2 = 1, nextTerm;
printf("请输入要输出的斐波那契数列的项数:");
scanf("%d", &n);
printf("斐波那契数列前 %d 项为:\n", n);
for (i = 1; i <= n; ++i) {
if (i == 1) {
printf("%lld, ", t1);
continue;
}
if (i == 2) {
printf("%lld, ", t2);
continue;
}
nextTerm = t1 + t2;
t1 = t2;
t2 = nextTerm;
printf("%lld, ", nextTerm);
}
return 0;
}
```
阅读全文