c++输出斐波那契数列示例分享

时间:2021-08-18 07:45:06

复制代码 代码如下:


#include "stdio.h"

 

int Feibo(int Num)
{
if(Num == 1 || Num == 2)
{
return 1;
}
else
{
return Feibo(Num - 1) + Feibo(Num - 2);
}
}

void main()
{
int NumIn,i;
scanf("%d", &NumIn);
for(i=1;i<NumIn;i++)
{
printf("%d ",Feibo(i));
}
printf("%d",Feibo(NumIn));
}