Without using arrays, write a complete program that reads three integers from the console and outputs the same three numbers in ascending order on separate lines. For example if the input is 5 4 3 then the output will be
3
4
5.
Do not prompt the user or produce any other output besides the three numbers with endlines.
Here is what I have for my solution:
#include<iostream>
using namespace std;
int main()
{
int k, m, n, swap;
cin >> k >> m >> n;
if(n < m && m < k)
{
cout << n << endl;
cout << m << endl;
cout << k << endl;
}
else if(m < n && n < k)
{
cout << m << endl;
cout << n << endl;
cout << k << endl;
}
else if(n < k && k < m)
{
cout << n << endl;
cout << k << endl;
cout << m << endl;
}
else if(k < n && n < m)
{
cout << k << endl;
cout << n << endl;
cout << m << endl;
}
else if(n < k && k < m)
{
cout << m << endl;
cout << k << endl;
cout << n << endl;
}
else
{
cout << k << endl;
cout << m << endl;
cout << n << endl;
}
return 0;
}
The actual output I am getting is:
2
1
3
Is there something that I am doing wrong? What do I need to change?