百鸡百钱问题:
C代码:
include <stdio.h>
main()
{
int cock, hen, chicken;
for(cock=0;cock<=20;cock++)
for (hen = 0; hen <= 33; hen++)
{
chicken = 100 - cock - hen;/
if (5 * cock + 3 * hen + chicken / 3.0 == 100)
printf("cock=%2d,hen=%2d,chicken=%2d\n", cock, hen, chicken);
}
return 0;
}
为何使用while循环写出来的代码无法编译出结果?求解答
include <stdio.h>
main()
{
int cock=0, hen=0, chicken = 0;
while (cock <= 20)
{
while (hen <= 33)
{
chicken = 100 - cock - hen;
if (5 * cock + 3 * hen + chicken / 3.0 == 100)
printf("cock=%2d,hen=%2d,chicken=%2d\n", cock, hen, chicken);
}
hen++;
cock++;
}
return 0;
}