C语言解决百钱百鸡问题(穷举法)
#include "stdio.h"main()
{
int x,y,z;
for(x=1;x<=20;x++)
for(y=1;y<=33;y++)
for(z=3;z<=99;z+=3)
{
if((5*x+3*y+z/3==100)&&(x+y+z==100))
printf("公鸡=%d,母鸡=%d,小鸡=%d\n",x,y,z);
}
}
2011-11-03 13:28
程序代码:#include "stdio.h"
main()
{
int x,y;
for(x=1;x<=20;++x)
for(y=1;y<=33;++y)
if(5*x+3*y+(100-x-y)/3==100 && (100-x-y)%3==0)
printf("公鸡=%d,母鸡=%d,小鸡=%d\n",x,y,100-x-y);
}

2011-11-03 14:42
2011-11-03 15:45
2011-11-03 17:39
2011-11-03 18:30