C语言百马百担

任务描述

本关任务:有100匹马,驮100担货,大马驮3担,中马驮2担,两匹小马驮1担,问有大、中、小马各多少?请累计所有的可能组合方案,以及每一种方案,以(大,中,小)的形式输出,如测试说明所示。

 

#include <stdio.h>
int main( void )
{
int x,y,z;
int sum=1;
int count=0;
for(x=0;x<=33;x++){
    for(y=0;y<=50;y++){
        z=100-x-y;
        if(x*3+y*2+z*0.5==100){
            count++;
            printf("%d,%d,%d\n",x,y,z);
        }
    }

}
printf("count=%d",count);
return 0;
}

 

posted @ 2022-03-09 11:09  程序员小贤  阅读(883)  评论(0)    收藏  举报