c++输出斐波那契数列示例分享
发布时间:2016-12-28 来源:查字典编辑
摘要:复制代码代码如下:#include"stdio.h"intFeibo(intNum){if(Num==1||Num==2){return1;...
复制代码 代码如下:
#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));
}