我正在尝试编写一个递归斐波那契生成器,用 C 语言打印每个项。项的数量是用户指定的;我已经开发了算法。当我尝试打印时,它只打印那些。谁能指出我哪里出错了?
#include <stdio.h>
#include <stdlib.h>
int Fibonacci (int n)
{
if (n = 0)
return 0;
if (n = 1)
return 1;
else
return (Fibonacci(n-1) + Fibonacci(n-2));
}
int main()
{
int terms;
printf("Enter the number of terms: ");
scanf("%d", &terms);
printf("\nThe Fibonacci sequence containing %d terms is:\n", terms);
int i = 0;
for (i; i < terms; i++)
{
printf("%d ", Fibonacci(i));
}
return 0;
}
最佳答案
if (n == 0)
不是
if (n=0)
仔细检查你的语法。
关于c - 无法正确打印递归斐波那契数列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38090131/