-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy path4_11_2.c
More file actions
33 lines (26 loc) · 875 Bytes
/
4_11_2.c
File metadata and controls
33 lines (26 loc) · 875 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*【例4-11-2】搬砖问题。某工地需要搬运砖块,已知男人一人搬3块,女人一人搬2块,小孩两人搬1块。
* 如果想用n人正好搬n块砖,问有那些搬法?*/
/* n人正好搬n块砖,程序版本2,二重循环 */
# include <stdio.h>
int main() {
int children, cnt, limit_m, limit_w, men, n, women;
/* 输入提示 */
printf("Enter n: ");
scanf("%d", &n);
limit_m = n / 3;
limit_w = n / 2;
cnt = 0;
for (men = 0; men <= limit_m; men++) {
for (women = 0; women <= limit_w; women++) {
children = n - men - women;
if ((men * 3 + women * 2 + children * 0.5 == n)) {
printf("men=%d, women=%d, children=%d\n", men, women, children);
cnt++;
}
}
}
if (cnt == 0) {
printf("None\n");
}
return 0;
}