猴子吃桃问题:
有一堆桃子,猴第一天吃了其中的一半并再多吃一个!以后每天猴子都吃其中的一半,然后再多吃一个 。当到第十天时 ,想再吃(还没吃),发现只有 1个桃子了 。问题:最初共多少个桃子 ?
#include<stdio.h>
int peach(int day) {
if (day == 10) {
return 1;
}
else {
return (peach(day + 1) + 1) * 2;
}
}
int main() {
int num = peach(1);
printf("%d", num);
return 0;
}
# 1534