关于百鸡百钱的输出问题!
#include <stdio.h>void 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++;
}
}
这个输出为
如果改成这样的话:
#include <stdio.h>
void 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.0)
printf ("%d %d %d\n", cocks, hens, chicks);
hens++;
}
cocks++;
}
}
输出为
我用的是VC++ 企业版;求解!!为什么会这样?
[ 本帖最后由 artofflive 于 2009-10-30 12:40 编辑 ]