公元钱五世纪,我国古代数学家张丘建在《算经》一书中提出了“百鸡问题”:鸡翁一值钱五,鸡母一值钱三,鸡雏三值钱一。百钱买百鸡,问鸡翁、鸡母、鸡雏各几何?
#include <stdio.h>
#include <stdlib.h>
int main(int argc,char *argv)
{
int cocks,hens,chicks;
for( cocks = 0; cocks < 20; cocks++ )
{
for( hens = 0 ; hens < 33; hens ++ )
{
chicks = 100 - cocks - hens;
if( ( 5*cocks+3*hens+chicks/3 == 100 ) && ( chicks % 3 == 0 ) )
{
printf("cocks:%d,hens:%d,chicks:%d",cocks,hens,chicks);
}
}
}
return 0;
}
cocks:0,hens:25,chicks:75
cocks:4,hens:18,chicks:78
cocks:8,hens:11,chicks:81
cocks:12,hens:4,chicks:84
sandbox> exited with status 0