URI Online Judge | 1042
Simple Sort
Read three integers and sort them in ascending order. After, print these values in ascending order, a blank line and then the values in the sequence as they were readed.
Input
The input contains three integer numbers.
Output
Present the output as requested above.
Input Sample | Output Sample |
7 21 -14 | -14 7 21 7 21 -14 |
-14 21 7 | -14 7 21 -14 21 7 |
Solution;
#include <stdio.h>
int main()
{
int a,b,c,min,mid,max;
scanf("%d %d %d",&a,&b,&c);
if(a < b && a < c){
min = a;
if(b < c){
mid = b;
max = c;
}else{
mid = c;
max = b;
}
}else if(b < a && b < c){
min = b;
if(a < c){
mid = a;
max = c;
}else{
mid = c;
max = a;
}
}else{
min = c;
if(a < b){
mid = a;
max = b;
}else{
mid = b;
max = a;
}
}
printf("%d\n%d\n%d\n", min, mid, max);
printf("\n%d\n%d\n%d\n",a,b,c);
return 0;
}
Post a Comment
0Comments