编写一个C++程序实现斐波那契数列
时间: 2023-03-12 10:10:29 浏览: 22
斐波那契数列c++实现(csdn)————程序.pdf
答:#include <stdio.h>
int main()
{
int n, first = 0, second = 1, next, c;
printf("输入项数: ");
scanf("%d", &n);
printf("斐波那契数列: ");
for (c = 0; c < n; c++)
{
if (c <= 1)
next = c;
else
{
next = first + second;
first = second;
second = next;
}
printf("%d\n", next);
}
return 0;
}
阅读全文