斐波那契的兔子

#include <stdio.h>
long fun(int month)
{
    if(month==1||month==2)
    return 1;
    else
    return fun(month-1)+fun(month-2); 
}
int main()
{
    int n,sum=0,mon=0;
    scanf("%d",&n);
    do{
        mon++;
        if(mon==1||mon==2){
            sum=1;
        }
        else{
            sum=fun(mon-1)+fun(mon-2);
        }
      }while(sum<n);
    printf("%d",mon);
    
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_42105789/article/details/81095520