如果是从小到大顺序输出,那么就改为如下代码:
#include <stdio.h>
int main(void)
{
int a , b , c;
int tmp;
char buf;
printf("请输入三个整数,以空格分隔:\n");
while(1) {
tmp = scanf("%d %d %d" , &a , &b , &c);
if(tmp<3) {
while((buf=getchar())!=EOF && buf!='\n');
fprintf(stderr , "输入的整数格式有误,请重新输入:\n");
continue;
}
break;
}
if(a < b) {
tmp = b;
b = a;
a = tmp;
}
if(a<c) {
tmp = c;
c = a;
a = tmp;
}
if(b<c) {
tmp = c;
c = b;
b = tmp;
}
printf("%d %d %d\n" , c , b , a);
return 0;
}