Write a function named sortie that takes three integer parameters by reference a
ID: 3864731 • Letter: W
Question
Write a function named sortie that takes three integer parameters by reference and rearranges them in ascending order--the first parameter being the smallest, the third parameter being the largest. A comment in the file indicates where the function should be written.
#include<iostream>
using namespace std;
// WRITE YOUR sortie FUNCTION HERE
int main()
{
cout << "Enter three numbers ";
int first, second, third;
cin >> first >> second >> third;
cout << endl;
cout << "Unsorted: " << first << ", " << second << ", " << third << endl;
sortie(first, second, third);
cout << "Sorted: " << first << ", " << second << ", " << third << endl;
return 0;
}
Explanation / Answer
#include<iostream.h>
#include<conio.h>
void sort(int *a, int *b)
{
if(*a>=*b)
{
int temp = *b;
*b=*a;
*a=temp;
}
}
void sortie(int *first, int *second, int *third)
{
sort(first,second);
sort(second,third);
sort(first,third);
}
int main()
{
cout<<"Enter three numbers:";
int first,second,third;
cin>>first>>second>>third;
cout<<endl;
cout<<"Unsorted:"<<first<<","<<second<<","<<third<<endl;
sortie(&first, &second, &third);
cout<<"Sorted: "<<first<<","<<second<<","<<third<<endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.