Question #38707

Write a program that asks the user for three numbers (use integers);
have the program print out the numbers in order of biggest to smallest.
Example:
Enter four numbers: 5
9
12
In order, they are: 12 9 5

Expert's answer

Answer on Question #38707 - Programming - C++

Below is the code of the required program in C++:


#include <iostream>
using namespace std;
int main() {
int a, b, c, temp;
cout << "Enter three numbers: ";
cin >> a >> b >> c;
if (a < b) {
temp = a;
a = b;
b = temp;
}
if (a < c) {
temp = a;
a = c;
c = temp;
}
if (b < c) {
temp = b;
b = c;
c = temp;
}
cout << "In order they are: " << a << " " << b << " " << c << endl;
return 0;
}
LATEST TUTORIALS
APPROVED BY CLIENTS