用C++写一个斐波那契数列
时间: 2023-03-08 18:18:43 浏览: 34
c++实现斐波那契数列
我可以用C语言写出斐波那契数列: #include<stdio.h> int main()
{
int i, n, t1 = 0, t2 = 1, nextTerm;
printf("输入项数: ");
scanf("%d", &n);
printf("斐波那契数列: ");
for (i = 1; i <= n; ++i)
{
printf("%d, ", t1);
nextTerm = t1 + t2;
t1 = t2;
t2 = nextTerm;
}
return 0;
}
阅读全文