百元买鸡问题:用100元买100只鸡,其中母鸡每只3元,公鸡每只2元,小鸡1元,且每种鸡至少买1只。

#include<stdio.h>
void main()
{
int x,y,z;
for(x=1;x<=32;x++)
{ for(y=1;y<=48;y++)
{ z=100-x-y;
if((z%3==0)&&(3*x+2*y+z/3==100))
{ printf("hen=%d,cock=%d,chicken=%d\n",x,y,z);
goto laber;
}
}
}
laber:;
}

posted on 2019-12-25 12:34  张德明  阅读(1586)  评论(0)    收藏  举报