Answer to Question #225300 in C++ for Ulando

Question #225300

Write a program that Will short thee integers .the integers are entered from the keyboard and stored in variable num1,num2,num3 respectively. The program sorts the numbers so that num1<=num2<=num3.


1
Expert's answer
2021-08-11T14:12:26-0400
#include<iostream>
using namespace std;
int main(){
	int temp;
	int element[3];
	cout<<"Enter the first number\n";
	cin>>element[0];
	cout<<"Enter the second number\n";
	cin>>element[1];
	cout<<"Enter the third number\n";
	cin>>element[2];
	cout<<"The elements entered before sorting are: \n";
	for(int i =0; i<3; i++){
		cout<<element[i]<<"\t";
	}
	for (int i = 0; i < 3 ; ++i)
	{
		for (int j = i + 1; j < 3; ++j) 
		{
			if (element[i] > element[j]) 
			{
				temp = element[i]; 
				element[i] = element[j]; 
				element[j] = temp; 
			}
		}
	}
	cout << "\nAfter sorting the elements\n:  ";
	for (int col = 0; col < 3; ++col)
		cout << element[col] << "\t";
}

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
APPROVED BY CLIENTS