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
1

Expert's answer

2014-01-29T12:53:08-0500

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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS