标签:pause \n code 答案 a* ble print amp 代码
类似问题主要是通过将所有可能列出一一排除的方式来输出正确答案由题知道大马最多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只\n", a, b, c);
system("pause");
return 0;
}
百马百驮问题,大马可驮3批货,中马2批,两匹小马一批货,大马中马小马各多少匹
标签:pause \n code 答案 a* ble print amp 代码
原文地址:https://blog.51cto.com/14232799/2364611