第四章例4-12

#include<stdio.h>
int main(void)
{
    int child,men,women;

    for(men=0;men<=45;men++)
        for(women=0;women<=45;women++)
            for(child=0;child<=45;child++)
                if(men+women+child==45&&men*3+women*2+child*0.5==45)
                    printf("men=%d,women=%d,child=%d\n",men,women,child);

    return 0;
}

#include<stdio.h>
int main(void)
{
    int child,women,men;

    for(men=0;men<=15;men++)
        for(women=0;women<=22;women++){
            child=45-women-men;
            if(men*3+women*2+child*0.5==45)
                printf("men=%d,women=%d,child=%d\n",men,women,child);
        }
    return 0;
}

 

posted @ 2013-10-03 09:43  wuyanlong  阅读(155)  评论(0)    收藏  举报