用C语言编程输入一个数n,输出斐波那契数列,这个数列包含n个元素。用#include“stdio” int main()展开·

2024-11-15 05:41:47
推荐回答(2个)
回答(1):

# include # include
int run(int n)
{
int sum=0;
if(n==1)
{
return 1;
}
if(n==2)
{
return 1;
}
sum=run(n-1)+run(n-2);
return sum;
}

void main()
{
int i;
for(i=1;i<=10;i++)
{
printf('%d\t',run(i));
}
printf('\n');
}

回答(2):

int Fshulie(int x)
{
if(x==1 || x==2)
return 1;
else
return Fshulie(x-1)+Fshulie(x-2);
}
int main()
{
int n,i;
scanf("%d",&n);
for(i=1;i<=n;++i)
{
printf("%d ",Fshulie(i));
}
printf("\n");
}