#include
#include
/*第n天所剩桃子数*/
int getPeachNumber (int n) {
int num; /*定义所剩桃子数*/
int i=0;
if (n==13)
return 1; /*递归结束*/
else {
num = getPeachNumber(n+1)*2 + 2; /*递归*/
printf("第%d天:%d个桃子\n", n, num); /*第n天剩num个桃子*/
}
return num;
}
int main (void) {
int num;
puts ("每天剩余的桃子数:");
num = getPeachNumber (1);
putchar ('\n');
puts ("================================================================");
putchar ('\n');
printf("猴子第一天摘了%d个桃子!\n", num);
putchar ('\n');
getch (); /*屏幕暂留*/
return 0;
}
运行结果
#include(stdio.h)
int main
{
int m=1,n=1;
whlie(n<=10)
{
m=m+m+2;
n++;
}
printf(“sum=%d\n”,m);
return 0;
}