C语言函数处理猴子吃桃子问题

来源:百度知道 编辑:UC知道 时间:2024/06/11 13:44:27
果园里面有一只猴子,还有一堆桃子,第一天猴子把桃子的一半吃了,然后扔掉剩下一半中的一个坏的,第二天,猴子又把现有的桃子吃掉一半,又扔掉一个坏的。这样,第三天,第四天。第五天。第六天,到第七天的时候桃子只剩下1个。求最初的时候有多少桃子
用C语言函数的方法,例如主函数是main(),子函数。。。。
例如#include "sstdio.h"
void main()
{
.....
}
int taozi(int n)
{
.....
}

main()
{
int day,x1,x2;
day=9;
x2=1;
while(day>0)
{
x1=(x2+1)*2;
x2=x1;
day--;
}
printf("the total is %d\n",x1);
getch();
}

#include <stdio.h> /*小猴吃梨问题*/
void main()
{
long x,y; /* 定义两个变量*/
x=1;
y=18;
clrscr();
puts(" This program is to solve");
puts(" The Problem of Child's Eating Pears.");
while(y>0)
{
x=2*(x+1);
y--;
}
printf(" >> In the first day, the child bought %ld pears.\n",x);
printf(" Press any key to quit...");
getch();
return;
}

C语言百例当中的
去看下吧
对你有帮助
咯咯

这是一个递推问题········自己在好好看看题·········