main()
{
float sn=100.0,hn=sn/2;
int n;
for(n=2;n<=10;n++)
{
sn=sn+2*hn;/*第n次落地时共经过的米数*/
hn=hn/2; /*第n次反跳高度*/
}
printf("the total of road is %f\n",sn);
printf("the tenth is %f meter\n",hn);
}
{
float sn=100.0,hn=sn/2;
int n;
for(n=2;n<=10;n++)
{
sn=sn+2*hn;/*第n次落地时共经过的米数*/
hn=hn/2; /*第n次反跳高度*/
}
printf("the total of road is %f\n",sn);
printf("the tenth is %f meter\n",hn);
}
题目:一只猴子摘了N个桃子第一天吃了一半又多吃了一个,第二天又吃了余下的
一半又多吃了一个,到第十天的时候发现还有一个.
本文通过一个猴子吃桃的递归问题,展示了如何利用编程语言解决实际问题的方法。该问题描述为:一只猴子摘了N个桃子,第一天吃了一半又多吃了一个,之后每天重复相同的过程,直到第十天时只剩下一个桃子。文章通过C语言代码示例来逐步解析这个问题。
2868

被折叠的 条评论
为什么被折叠?



