递归猴子偷桃子

#include<strio.h>

int fun(int i)

{

                if(10==i)

                  return 1

                 return  (fun(i+1)+1)*2

}

int main()

{

              printf("%d\n",fun(1));

}

因为只知道猴子第十天剩了一个桃子,只能反方向推导,

1            fun(1)

(fun(1)+1)*2   fun(2)

(fun(2+1)+1)*2    fun(3)

这样就很容易的用递归算出

猜你喜欢

转载自blog.csdn.net/weixin_40989362/article/details/81103574