写一个c语言斐波那契数列
时间: 2023-03-13 15:22:49 浏览: 99
c语言斐波那契数列
5星 · 资源好评率100%
我可以用以下的 C 语言代码来写出斐波那契数列: #include <stdio.h>
int main()
{
int n, first = 0, second = 1, next, c;
printf("输入您想要的斐波那契数列的项数:");
scanf("%d", &n);
printf("斐波那契数列:\n");
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;
}
阅读全文