问题描述:一只公鸡值五钱,一只母鸡值三钱,三只小鸡值一钱,现要用百钱买百鸡,公鸡,母鸡,小鸡各多少只?
问题分析:设三个未知数x,y,z
x+y+z=100
5x+3y+z/3=100
完整程序:
#include<stdio.h>
int main()
{
int cock,hen,chicken;
for(cock=0,cock<=20,cock++)
for(hen=0,hen<=33,hen++)
for(chicken=0,chicken<=100,chicken++)
{
if(5*cock+3*hen+chicken/3.0==100)&&(cock+hen+chicken==100)
printf("cock=%2d,hen=%2d,chicken=%2d\n",cock,hen,chicken);
}
}
标签:2d,int,百钱,问题,100,百鸡,chicken,cock,hen From: https://www.cnblogs.com/zjm921/p/17327509.html