0

Why does this fail when I input 3, 2, 1?

I cannot figure out where I need to swap the values can anyone help me figure out the swap between x and y? https://code.sololearn.com/cgzvC40z3Ix8/?ref=app

27th Jan 2020, 8:48 PM
Haze
2 Answers
0
Haze #include <iostream> using std::cin; using std::cout; using std::endl; int main(){ // inputs the numbers cout << "Enter three numbers: "; int x, y, z; cin >> x >> y >> z; int tmp; // orders x and y if (x > y){ tmp = x; x = y; y = tmp; } // orders y and z if (y > z){ tmp = y; y = z; z = tmp; } //You need this if (x > y){ tmp = x; x = y; y = tmp; } // outputs the sorted numbers cout << "The sorted numbers are: "; cout << x << " " << y << " " << z << endl; }
29th Jan 2020, 3:08 AM
Sp Maurya
Sp Maurya - avatar