Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions