1. Write a program that takes input of three integers from theuser, and prints t
ID: 3614086 • Letter: 1
Question
1. Write a program that takes input of three integers from theuser, and prints the three numbers is an ascending order. Besidesthe main() function, your program should contain two otherfunctions. The prototypes of the two functions are given as thefollowing:void sort2(int & a, int & b);
This function swaps the values of a and b if a is greater than b,and leaves a and b unchanged otherwise. (Note: both a and b arereference parameters)
void sort3(int & a, int & b, int & c);
This function swaps its three parameters to arrange them in sortedorder. (Note: a, b, and c are all reference parameters).
Explanation / Answer
I am glad to help you...(Pleaserate my answer) include<iostream> using namespace std; // First we create themethods void sort2(int a, int b) { if (a>b) { int num; num=a; a=b; b=temp; } }void swap3(int a, int b, int c) { int num; if(a>b) { num=a; a=b; b=num;
} if (b>c) { num=b; b=c; c=num; } if (c>a) { num=c; c=a; a=num; } }
// This is place where you ask the userto input and store the input and do necessaryoperations.
int main()
{
int num1, num2, num3;
cout<<"enter num1: ";
cin>>num1;
cout<<endl<<"enter num2: ";
cin>>num2;
cout<<endl<<"enter num3: ";
cin>>num3;
cout<<endl<<"num1:"<<num1<<" num2:"<<num2<<" num3:"<<num3<<endl;
swap3(&num1, &num2, &num3);
cout<<endl<<"num1: "<<num1<<" num2: "<<num2<<" num3:"<<num3<<endl;
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.