Here is code in C++.
#include <bits/stdc++.h>
// include header
using namespace std;
// function to rearrangement the numbers
void Sort(int& i, int& j, int& k)
// values are passed by reference
{
// first parameter gets largest value
if(i<j){
// swap the value of i & j
int tmp = i;
i = j;
j = tmp;
}
//second parameter gets second largest value
if(i<k){
// swap the value of i & k
int tmp = i;
i=k;
k = tmp;
}
//third parameter gets smallest value
if(j<k){
// swap the value of k & j
int tmp = j;
j=k;
k=tmp;
}
}
// driver function
int main() {
cout << "Enter three integers: " << endl;
// declaring 3 variables
int num1,num2,num3;
// reading the input
cin >> num1 >> num2 >> num3;
// calling the function
Sort(num1,num2,num3);
// printing the numbers after rearrangement
std::cout<<"Numbers after rearrangement: \\"<< num1 << " " << num2 << " " << num3 << std::endl;
// main ends here
return 0;
}
Step-by-step explanation:
First reading three integer in three different variables namely "num1","num2" and "num3".Pass these variable by reference in the function "sort()". There after comparing value of these three, largest value is assigned to num1, second largest value assigned to num2 and smallest value assigned to num3. Then it will print these value.
Output:
Enter three integers:
20 10 30
Numbers after rearrangement:
30 20 10