C语言编程百马百担问题,大马可驮3批货,中马2批,两匹小马一批货,大马中马小马各多少匹...

类似问题主要是通过将所有可能列出一一排除的方式来输出正确答案

由题知道大马最多33匹,中马最多50匹,小马最多100匹--由此可得循环判断条件

源代码如下

#include<stdio.h>
#include<stdlib.h>
int main()
{
    int Bh = 3, Mh = 2;
    int a, b, c;
    double Lh = 0.5;
    for (a = 1; a <34;a++)//大马个数
    for (b = 1; b <51;b++)//中马个数
    for (c = 2; c <101;c++)//小马个数
    if (((a*Bh) + (b*Mh) + (c*Lh) )== 100&&(a+b+c)==100)题目条件
        printf("大马有%d只,中马有%d只,小马有%d只
", a, b, c);
    system("pause");
    return 0;
}
原文地址:https://www.cnblogs.com/Kaniso-Vok/p/13756280.html