C语言: 36块砖,36人搬:一男搬4块,1女搬3块,两小孩抬一块,一次全部搬完。问男、女、小孩人数各若干?


谢谢回答
#include <stdio.h>
void main()
{
int a=0,b=0,c=0; // a->男, b->女, c->小孩,变量初始化为0

while(a<=36)
{
b=0;

while(b<森差=36)
{
c=36-a-b;

if(c>=0)
{
if((36==a*4+b*3+c/2)&&(0==c%2)) //小孩个数需要为偶数才成立
printf("男人:%d 女人察肆:%d 小孩:%d\n",a,b,c);
}

b++;
}

a++;
}
}

output:败春轿

男人:3 女人:3 小孩:30
请按任意键继续. . .
#include<stdio.h>
void main()
{
int man,woman,child;
for(man=0;man<=9;man++)
{for(woman=0;woman<=12;woman++)
{child=36-man-woman;
if(man*4+woman*3+child/2.0==36)
printf("成年腊裤男轮桐简子:%d人,成年女轮衡子:%d人,儿童:%d人\n",man,woman,child);
}
}
}
30小孩 3男人 3女人
#include <stdio.h>
int main()
{
int men=0,women=0,children=0;

for(men=0; men<36; men++)
{
for(women=0; women<36-men; women++)
{
children=36-men-women;
if(children<0)
continue;
if((men*4+women*3+children/2)==36)
printf("men: %d, women: %d, children: %d\n", men,women,children);
}
}
return 0;
}
void main()
{
int n_man=0;
int n_woman=0;
int n_child=0;
for(n_man=0;n_man<36;n_man++)
for(n_woman=0;n_woman<36;n_woman++)
for(n_child=0;n_child<36;n_child++)
{
if(( n_man+n_woman+n_child==36)&&(n_man*4+n_woman*3+n_child/2==36)
&&(n_child%2==0) )
printf("%d\n%d\n%d\n\n\n",n_man,n_woman,n_child);

}

}