Receive 3 numbers and display them in ascending order from smallest to largest
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int x, y, z;
cout << "Enter the first number: ";
cin >> x;
cout << "Enter the second number: ";
cin >> y;
cout << "Enter the third number: ";
cin >> z;
if (x > y) {
swap(x, y);
}
if (y > z) {
swap(y, z);
}
if (x > y) {
swap(x, y);
}
cout << "\nYour numbers in ascending order from smallest to largest: " << endl;
cout << x << ' ' << y << ' ' << z << endl;
return 0;
}
Comments
Leave a comment