猴子吃桃问题代码
仍记得这是C语言实验课上的一次作业,写好后没带U盘就发到编程爱好者博客上来了,这次转过来也感受一下上课的感觉。
#include
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));
}
}
阅读(742) | 评论(0) | 转发(0) |