斐波那契数列:2.迭代法
#include <stdio.h>
int fib(int m)
{
if(m==1||m==2)
{
return 1;
}
int a=1,b=1,aw=0;
while(m>=2)
{
aw=aw+a;
a=b;
b=aw;
m=m-1;
}
return aw;
}
int main()
{
int n;
scanf("%d",&n);
printf("%d",fib(n));
return 0;
}
标签:return,int,斐波,aw,迭代法,那契
From: https://www.cnblogs.com/yesiming/p/17441641.html