编写程序解公一只值5,母一只值3,小3只值1,有100,问各多少?

来源:百度知道 编辑:UC知道 时间:2024/07/05 09:20:08
很急,谢谢了

//公鸡一只5钱,母鸡一只3钱,雏鸡3只一钱,公鸡,母鸡,雏鸡数量分别为x,y,z
#include <stdio.h>
void main()
{
int x, y, z;
for(x = 0; x < 20; x++)
for(y = 0; y <= 33; y++)
for(z = 0; z <= 100; z++)
if(x + y + z == 100 && 15 * x + 9 * y + z == 300)
printf(" %d\t%d\t%d\n ", x, y, z);
}

int x;//公
int y;//母
int z;//小
//5x+3y+z/3=100
//x+y+z=100
for(x=0;x<=20;x++)
for(y=0;y<33;y++)
if((100-x-y)%3==0&&x*5+y*3+(100-x-y)/3==100)
printf("%d%,%d,%d\n",x,y,100-x-y);