#include <stdio.h>
int main()
{
int a,b,c,d;
scanf("%d %d %d %d",&a,&b,&c,&d);
int t;
int max;
if(a>b)
{
t = a;
a = b;
b = t;
}
if(a>c)
{
t = a;
a = c;
c = t;
}
if(a>d)
{
t = a;
a = d;
d = t;
}
if(b>c)
{
t = b;
b = c;
c = t;
}
if(b>d)
{
t = b;
b = d;
d = t;
}
if(c>d)
{
t = c;
c = d;
d = t;
}
printf("%d %d %d %d\n",a,b,c,d);
return 0;
}
int array[4];
int i,temp,j;
for (i=0;i<4;i++)
scanf("%d",&array[i]);
for (i=0;i<3;i++)
for (j=0;j<4-i-1;j++){
if (array[j]>array[j+1]){
temp = array[j];
array[j] = array[j+1];
array[j+1] = temp;
}
}
for (i=0;i<4;i++)
printf("%d ",array[i]);
#include <stdio.h>
int main()
{
int a, b, c, d;
int max_num;
scanf_s("%d %d %d %d", &a, &b, &c, &d);
int tmp;
//找到最小的数
if (a > b) {
tmp = a; a = b; b = tmp; // a>b两个数据交换,则给a存储小的b
}
if (a > c) {
tmp = a; a = c; c = tmp;
}
if (a > d) {
tmp = a; a = d; d = tmp;
}
//找到第二小的数,不需要和最小的数比较
if (b > c) {
tmp = b; b = c; c = tmp;
}
if (b > d) {
tmp = b; b = d; d = tmp;
}
//找到第三小的数据,不需要和第一和第二小比较
if (c > d) {
tmp = c; c = d; d = tmp;
}
printf("%d %d %d %d\n", a, b, c, d);
system("pause");
return 0;
}
登录后提交答案