//斐波拉契1,1,2,3,5,8...
#include
int main()
{
int f1,f2,f3;
int n;
int i;
f1=1;
f2=1;
printf("请输入数的序号:");
scanf("%d",&n);
if (1==n)
{
f3=1;
}
else
{
for (i=3;i<=n;++i)
{
f3=f2+f1;
f1=f2;
f2=f3;
}
}
printf("fn=%d\n",f3);
return 0;
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)