#include <stdio.h>
#include <stdlib.h>
int feibo(int n);//非递归
int feiboDigui(int n);//递归
int main()
{
int n;
while(scanf("%d",&n)!=EOF){
printf("%d\n",feiboDigui(n));//目前是递归方法,非递归换一下就ok
}
return 0;
}
int feibo(int n){//非递归
int sum1 = 1,sum2 = 1, sum,i;
if(n == 1){
return 1;
}
if(n == 2){
return 1;
}
for(i=3;i<=n;i++){
sum = sum1+sum2;
sum1 = sum2;
sum2 = sum;
}
return sum;
}
int feiboDigui(int n){
if(n==1||n==2){ //递归函数出口
return 1;
}else{
return (feiboDigui(n-2)+feiboDigui(n-1));
}
}
来源:CSDN
作者:hj_cheng29
链接:https://blog.csdn.net/qq_40604352/article/details/104553292