Arrange the Numbers in Descending Order
Here you will get an example code of C++ program to arrange the numbers in descending order. This is the basic example of nested if-else (conditional statement).
Example to arrange the numbers in descending order
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | #include <iostream> using namespace std; int main() { int a, b, c, g1, g2, g3; cout<<"\nProgram to print three numbers in descending order\n"; cout << "\nEnter three numbers: "; cin >> a >> b >> c; if (a > b && a > c) { g1=a; if (b > c) { g2=b;g3=c; } else { g2=c;g2=b; } } else if (b > a && b > c) { g1=b; if (a > c) { g2=a;g3=c; } else { g2=c;g3=a; } } else { g1=c; if (a > b) { g2=a;g3=b; } else { g2=b;g3=a; } } cout<<"\n"<<g1<<" "<<g2<<" "<<g3; return 0; } |
Output
Check out our other C++ programming Examples