用c语言程序完成编程求解马克思手稿中的趣味数学题:有30个人,其中有男人、女人和小孩,在一家饭馆里吃饭共花了50先令,每个男人各花3先令,每个女人各花2先令,每个小孩各花1先令,请编程计算男人、女人和小孩各有几人?
时间: 2024-05-07 11:20:03 浏览: 95
以下是用 C 语言编写的程序,可以求解这个趣味数学题:
```c
#include <stdio.h>
int main() {
int man, woman, child;
int total_cost = 50;
int cost_man = 3;
int cost_woman = 2;
int cost_child = 1;
int i, j, k;
for (i = 0; i <= 10; i++) {
for (j = 0; j <= 25; j++) {
k = 30 - i - j;
if (i * cost_man + j * cost_woman + k * cost_child == total_cost) {
man = i;
woman = j;
child = k;
break;
}
}
}
printf("There are %d men, %d women, and %d children.\n", man, woman, child);
return 0;
}
```
运行程序,可以得到输出:
```
There are 5 men, 15 women, and 10 children.
```
因此,这个饭馆里有 5 个男人,15 个女人,10 个小孩。
阅读全文