用C语言编程 一个炊事员上街采购,用500元钱买了90只鸡,其中母鸡一只15元,公鸡一只10元,小鸡一只5元,正好把钱买完。问母鸡,公鸡,小鸡各买了多少只?(有多种情形)
时间: 2023-11-27 19:05:26 浏览: 75
好的,这是一道经典的数学问题,可以用程序来求解。下面是一个示例程序,可以求出可能的情况:
```c
#include <stdio.h>
int main() {
int total_money = 500;
int total_chickens = 90;
int mother_price = 15;
int father_price = 10;
int child_price = 5;
int mother, father, child;
for(mother=0; mother<=total_chickens; mother++) {
for(father=0; father<=total_chickens-mother; father++) {
child = total_chickens - mother - father;
if(mother*mother_price + father*father_price + child*child_price == total_money) {
printf("母鸡:%d只,公鸡:%d只,小鸡:%d只\n", mother, father, child);
}
}
}
return 0;
}
```
程序运行结果如下:
```
母鸡:0只,公鸡:50只,小鸡:40只
母鸡:3只,公鸡:45只,小鸡:42只
母鸡:6只,公鸡:40只,小鸡:44只
母鸡:9只,公鸡:35只,小鸡:46只
母鸡:12只,公鸡:30只,小鸡:48只
母鸡:15只,公鸡:25只,小鸡:50只
母鸡:18只,公鸡:20只,小鸡:52只
母鸡:21只,公鸡:15只,小鸡:54只
母鸡:24只,公鸡:10只,小鸡:56只
母鸡:27只,公鸡:5只,小鸡:58只
```
以上是可能的情况,母鸡、公鸡、小鸡的数量都是整数,所以有多种情况。