关于三个数大小排序问题,求解答!!!
一是视频里我照着敲出来的,能运行但是有时候不能正确排序。然后我又琢磨了一下写出二就正确了。我想问一为什么有的情况不能正确排序?百度上也是一这种写法。我用的vs2015.一,视频里教的
#include<stdio.h>
void main()
{
int a, b, c, d;
printf("Please enter three numbers:\n");
scanf("%d%d%d",&a,&b,&c);
if (a > b)
{
d = a; a = b; b = d;
}
if (a > c);
{
d = a; a = c; c = d;
}
if (b > c)
{
d = b; b = c, c = d;
}
printf("%d %d %d", a, b, c);
}
二,我自己改进的
#include<stdio.h>
void main()
{
int a, b, c, d;
printf("Please enter three numbers:\n");
scanf("%d%d%d",&a,&b,&c);
if (a > b)
{
d = a; a = b; b = d;
}
if (a > c)
{
d = a, a = c, c = b; b = d;
printf("%d %d %d",a,b,c);
}
else if (b > c)
{
d = b; b = c; c = d;
printf("%d %d %d",a,b,c);
}
else
{
printf("%d %d %d",a,b,c);
}
} ba21 发表于 2017-7-22 17:03
视力好{:5_109:}多谢
页:
[1]