Answer:
C++ Code:
void sort3(double &a, double &b, double &c)
{
if(a > b)
swapdoubles(a,b);
if (b > c)
swapdoubles(b,c);
if (a > b)
swapdoubles(a,b);
}
Step-by-step explanation:
To change the values of a,b,c within the function, we pass the values by reference. Let us assume that number a = 3.14, b = 2.71, c = 3.04. Since a > b, values of a and b will be swapped.Now a = 2.71 and b = 3.14. Similariy, since b > c, they will be swapped. This way, we move the largest number to its correct position in the first two steps. If there are only three numbers, and the largest number is in its correct position, then for the two remaining numbers, we will only need atmost one swap to exchange their positions. hence, we perform a comparison of a > b once again to see if the b is smaller than a. if its not, then all a,b,c are in sorted order.