Question: Solve this problem using pointer variables wherever possible. to be completed in C Problem - sort 3 numbers Modify the sort 3 program you previously

Solve this problem using pointer variables wherever possible.

to be completed in C

Problem - sort 3 numbers

Modify the sort 3 program you previously wrote, to use pointers. In main( ) read 3 numbers from the user into low, medium, high, then call a function to sort them. That is, if low = 50, medium = 10 and high = 30 before the function is called, then after the function call the variables will contain low = 10, medium = 30 and high = 50. Print out the values of low, medium and high before and after the function call.

The sort function needs only 3 separate if statements (with no else). Each if statement should call a swap function. The first two if statements should ensure that low has the correct value. The final if statement will ensure medium and high are correct.

The code for the sort function and swap function should come after main( ) so youll need prototypes. All parameter passing should be done via pointers.

In main call the sort function with these 3 different data sets, writing out the values for low, medium and high before and after calling the sort function in each case:

low = 50, medium = 10, high = 30

low = 30, medium = 50, high = 10

low = 50, medium = 30, high = 10

Note: think very carefully about the parameters in each function.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!