编写一个C++程序实现斐波那契数列
时间: 2023-03-07 10:20:22 浏览: 52
C++语言实现斐波那契数列.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;
}
阅读全文