百钱买百鸡的一个奇怪的问题
张丘建《算经》中提出“百鸡问题”:鸡翁一值钱五,鸡母一值钱三,鸡雏三值钱一。百钱买百鸡,问鸡翁、母、雏各几何?
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++;
}
}
为什么程序已经编绎连接成功了,就是输不出结果,就大侠们指教~~!!
参考答案:main( )
{
int cocks,hens,chicks;
cocks=0;
while(cocks<=19)
{
hens=0;
while(hens<=33)
{
chicks=100-cocks-hens;
if(5*cocks+3*hens+chicks/3==100&&chicks%3==0)
printf("%d,%d,%d\n",cocks,hens,chicks);
hens=hens+1;
}
cocks=cocks+1;
}
}