斐波那契数列(c语言)
时间: 2023-10-29 13:51:05 浏览: 60
斐波那契数列C语言
#include <stdio.h>
int main() {
int n, t1 = 0, t2 = 1, nextTerm = 0;
printf("输入一个正整数:");
scanf("%d", &n);
printf("斐波那契数列:");
for (int i = 1; i <= n; ++i) {
// 输出第i个斐波那契数列的数
printf("%d, ", t1);
nextTerm = t1 + t2;
t1 = t2;
t2 = nextTerm;
}
return 0;
}
阅读全文