《算经》中的百钱买百鸡问题:鸡翁一,值钱五,鸡母一,值钱三,鸡雏三,值钱一,百钱买百鸡,问翁,母,雏各几何?
- # include <stdio.h>
- int main()
- {
- int coke, hen, chick; //定义三个变量 表示 公鸡 母鸡 鸡雏!
- for (coke = 0; coke <= 20; coke++)
- {
- for (hen = 0; hen <= 33; hen++)
- {
- for (chick = 0; chick <= 99; chick += 3)
- {
- if (coke + hen + chick == 100)
- {
- if (coke * 5 + hen * 3 + chick / 3 == 100)
- printf("公鸡:%d 母鸡:%d 鸡雏:%d\n", coke, hen, chick);
- }
- }
- }
- }
- return 0;
- }
复制代码
|
|