<?phpheader("content-type:text/html;charset=utf-8");/*有一堆桃子,猴子第一天吃了其中的一半,并再多吃了一个!以后每天猴子都吃其中的一半,然后再多吃一个。当到第十天时,想再吃时(即还没吃),发现只有1个桃子了。问题:最初共多少个桃子?*/ ???function ct($n){ ???????????if($n==1){ //一天吃完 ???????????????return 1; ???????????}else{ ???????????????return 2*(ct($n-1)+1);//n天吃的时候剩一个 ???????????} ???} ???$a=ct(10); ???echo $a;//返回总桃子数 ???/*function ct($n){ ???????????if($n==10){ ???????????????return 1; ???????????}else{ ???????????????return 2*(ct($n+1)+1); ???????????} ???} ???$a=ct(1); ???echo $a; ???*/
php猴子吃桃
原文地址:http://www.cnblogs.com/lovebing/p/7612102.html