Write a program that prompts the user to input three numbers

Write a program that prompts the user to input three numbers. The program should then output the numbers in ascending order.

Solution

Ascending.cpp

#include <iostream>

using namespace std;

int main()
{
int a,b,c;
  
cout << \"Enter first value: \";
cin >> a;

cout << \"Enter second value: \";
cin >> b;

cout << \"Enter third value: \";
cin >> c;

if ((a > b && a > c))
{
if(b > c)
{
cout<<c <<\" \"<< b <<\" \" <<\" \"<< a;
}
else
cout<<b <<\" \"<< c <<\" \" <<\" \"<< a;
}
else if ((b > a && b > c))
{
if(a > c)
{
cout<<c <<\" \"<< a <<\" \" <<\" \"<< b;
}
else
{
cout<<a <<\" \"<< c <<\" \" << b;
}
}
else if ((c > a && c > b))
{
if(a > b)
{
cout<<b <<\" \" <<a <<\" \"<< c;
}
else
cout<<a <<\" \"<< b <<\" \"<< c;
}
cout<<endl;

return 0;
}

Output:

sh-4.3$ main                                                                                                                                                                                                                

Enter first value: 4                                                                                                                                                                                                        

Enter second value: 1                                                                                                                                                                                                       

Enter third value: 2                                                                                                                                                                                                        

1 2  4                                                                                                                                                                                                                      

sh-4.3$ main                                                                                                                                                                                                                

Enter first value: 2                                                                                                                                                                                                        

Enter second value: 4                                                                                                                                                                                                       

Enter third value: 3

2 3 4

 Write a program that prompts the user to input three numbers. The program should then output the numbers in ascending order.SolutionAscending.cpp #include <
 Write a program that prompts the user to input three numbers. The program should then output the numbers in ascending order.SolutionAscending.cpp #include <

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site