Example 4-3 Compare and exchange 3 real values, and output them in order
Title description
Input 3 real numbers a, b, c from the keyboard, and store the minimum value in variable a, the maximum value in variable c, and the intermediate value in variable b through comparison and exchange, in the order from smallest to largest Output these three numbers a, b, c.
Line feed is output at the end.
Input
Input separated by a space of three real
output
in ascending order of the output of the three real numbers, separated by a space intermediate, minimum front, after a maximum value. Keep 2 decimal places after the decimal point.
Note the newline at the end.
Sample input Copy
3 7 1
Sample output Copy
1.00 3.00 7.00
#include <stdio.h>
int main() {
double a, b, c;
scanf("%lf%lf%lf", &a, &b, &c);
if (a > b) {
if (b > c) {
printf("%.2f %.2f %.2f", c, b, a);
} else {
if (a > c) {
printf("%.2f %.2f %.2f", b, c, a);
} else {
printf("%.2f %.2f %.2f", b, a, c);
}
}
} else {
if (c > b) {
printf("%.2f %.2f %.2f", a, b, c);
} else {
if (a > c) {
printf("%.2f %.2f %.2f", c, a, b);
} else {
printf("%.2f %.2f %.2f", a, c, b);
}
}
}
return 0;
}