#include <stdio.h>
int remain(int i)
{
int j;
if(i==10)
j=1;
else if(i<10&&i>0)
j=(2*remain(i+1))+2;
else if (i<=0)
j=remain(1);
else if(i>10)
j=0;
return(j);
}
void main()
{
int a,b;
printf("please input the day you want to kown how many peach remained:\n");
scanf("%d",&a);
if(a>10)printf("The peach is eaten out.\n");
else if(a<=0)printf("The peach is not eatean,so have %d peach.\n",remain(1));
else
{
for(b=a;b>=1;b--)
printf("The %d day reamins %d peach.\n",b,remain(b));
}
}
正文
猴子吃桃问题代码2007-10-26 20:32:00
【评论】 【打印】 【字体:大 中 小】 本文链接:http://blog.pfan.cn/yanyoushuai/30510.html
阅读(1906) | 评论(0)
版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!
评论