百钱买百鸡问题,求解错在哪里。刚开始学C语言,如有语法错误请指正。
# include <stdio.h>int main(void)
{
int x ,y ,z ,a ,s ,d;
a=5,s=3,d=1;
printf("设公鸡x个,母鸡y个,小鸡z个。\n");
printf("公鸡一只5钱,母鸡一只3钱,小鸡三只1钱。\n");
for (x=1,x*a<=100,x+=1)
{
for (y=1,x*a+y*s<=100,y+=1)
{
for(z=1,x*a+y*s+z*d<=100,z+=1)
{
if(x*a+y*s+z*d==100 || x+y+z*3==100)
{
z*=3
printf("x=%d,y=%d,z=%d",x,y,z);
printf("公鸡%d只,母鸡%d只,小鸡%d只",x,y,z);
}
}
}
}
return 0;
}