猴子吃桃问题:猴子第一天摘下若干个桃子,当即吃了一半,还不过瘾,又多吃了一个 第二天早上又将剩下的桃子吃掉一半,又多吃了一个。以后每天早上都吃了前一天剩下 的一半加一个。到第n天早上想再吃时,见只剩下一个桃子了。问第一天共摘了多少个桃子?试编写相应程序(提示:采取逆向思维的方法,从后往前推断)
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<math.h>
int main(void) {
int n = 10, i, total=1;
for (i = n; i > 1; i--) {
total = 2*(total + 1);
printf("%d# = %d\n", i-1, total);
}
return 0;
}
#include <cstdio> int main(){ int apple=1,day =10; while(1){ day--; if(day==0) break; apple = (apple+1)*2; printf("第%d天的为:%d\n",day,apple); } printf("%d",apple); return 0; }