比较三个数的大小,取最小最大值 (尽管这个代码有点啰嗦)为什么运行后得不到正...
#include <stdio.h>int main()
{
int a,b,c;
printf("please input three numbers: ");
scanf("%d%d%d",&a,&b,&c);
if(a<b<c)
{
printf("min=%dmax=%d\n",a,c);
}
else if(b<c<a)
{
printf("min=%dmax=%d\n",b,a);
}
else if(c<a<b)
{
printf("min=%dmax=%d\n",c,b);
}
else if(c<b<a)
{
printf("min=%dmax=%d\n",c,a);
}
else if(a<c<b)
{
printf("min=%dmax=%d\n",a,b);
}
else if(b<a<c)
{
printf("min=%dmax=%d\n",b,c);
}
} {:9_221:} 不可以直接用a<b<c这里边会先执行a<b或b<c他们的返回值是0或1,结果自然会不一样。 DASHUAIZI 发表于 2018-8-4 22:41
不可以直接用a
哦{:7_113:} #include <stdio.h>
int main()
{
int a,b,c,min,max;
printf("please input three number: ");
while(scanf("%d %d %d",&a,&b,&c))
{
max=(a>b?(a>c?a:c):(b>c?b:c));
min=(a<b?(a<c?a:c):(b<c?b:c));
printf("min=%d,max=%d\n",min,max);
printf("please input three number(q to quit): ");
}
return 0;
}
页:
[1]