[c语言][100例题]三者比较
本帖最后由 My_A 于 2019-4-5 13:33 编辑#include <stdio.h>
/*
题目:输入三个整数x,y,z,请把这三个数由小到大输出。
*/
int main()
{
int x1,x2,x3;
int r1,r2,r3; // 保存排序后的结果
printf("请输入3个数:");
scanf("%d %d %d",&x1,&x2,&x3);
r1 = x1;
r2 = x2;
r3 = x3;
if(x1>x2){
if(x2>x3){
r1 = x1;
r2 = x2;
r3 = x3;
}else if(x1>x3){
r1 = x1;
r2 = x3;
r3 = x2;
}else {
r1 = x3;
r2 = x1;
r3 = x2;
}
}else if(x2>x3){
if(x1>x3){
r1 = x2;
r2 = x1;
r3 = x3;
}else{
r1 = x2;
r2 = x3;
r3 = x1;
}
}else{
r1 = x3;
r2 = x2;
r3 = x1;
}
// 判断是否有相等的情况
printf("排序: %d %c %d %c %d",r1,(r1==r2 ? '=' : '>'),r2,(r2==r3 ? '=' : '>'),r3);
return 0;
}
页:
[1]