我做个这题,改变一点点就有二种不同的答案,看看,为什么呢?
第一种
#include<stdio.h>
main ()
{
int cocks=0, hens, chicks;
while (cocks<=19)
{
hens=0;
while (hens<=33)
{chicks=100-cocks-hens;
if (5*cocks+3*hens+chicks/3==100)
printf (" %d %d %d\n", cocks, hens, chicks);
hens++;
}
cocks++;
}
}
结果是:0 25 75
3 20 77
4 18 78
7 13 80
8 11 81
11 6 83
12 4 84
第二种
#include<stdio.h>
main ()
{
int cocks=0, hens, chicks;
while (cocks<=19)
{
hens=0;
while (hens<=33)
{chicks=100-cocks-hens;
if (5.0*cocks+3.0*hens+chicks/3.0==100)
printf (" %d %d %d\n", cocks, hens, chicks);
hens++;
}
cocks++;
}
}
结果是:0 25 75
4 18 78
8 11 81
12 4 84
主要是这里啊,稍稍改变一下就没同了
if (5.0*cocks+3.0*hens+chicks/3.0==100)
请教高手,多谢!~