Problem link Click here
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, g, m, s, temp;
scanf("%d %d %d", &a, &b, &c);
g = a;
m = b;
s = c;
if (g < m){
temp = g;
g = m;
m = temp;
}
if (m < s){
temp = m;
m = s;
s = temp;
}
if (g < m){
temp = g;
g = m;
m = temp;
}
printf("%d\n%d\n%d\n\n%d\n%d\n%d\n",s,m,g,a,b,c);
return 0;
}
No comments:
Post a Comment