Answer to Question #280832 in C++ for ahmad

Question #280832

sorting 5 numbers using the basics (without array)


1
Expert's answer
2021-12-20T09:57:39-0500
#include <iostream>
#include <algorithm>


int main() {
    int a = 3, b = -1, c = 0, d = 5, e = 4;
    if (a > b) { std::swap(a, b); }
    if (c > d) { std::swap(c, d); }
    if (a > c) { std::swap(a, c); }
    if (b > d) { std::swap(b, d); }
    if (b > c) { std::swap(b, c); }


    if (a > e) { std::swap(a, e); }
    if (b > e) { std::swap(b, e); }
    if (c > e) { std::swap(c, e); }
    if (d > e) { std::swap(d, e); }


    std::cout << a << " " << b << " " << c << " " << d << " " << e << '\n';
    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!

Leave a comment

LATEST TUTORIALS
New on Blog