Bryjaun R.

asked • 10/13/22

Computer Programming

Objective

Make a function that sorts an array of doubles and returns the average and the median values from the array. NOTE: Pass by reference is REQUIRED for full credit.

Details

Begin by using the following array of data within your main function:

    double values[15] = { 7.7, 1001.2, 654.7, 12.8, 0.91, 15.102, 812.5, 121.6, 382.1,
                          40.1, 452.0, 128.2, 544.6, 23.2, 750.1 };

Next, create a separate function that has the following parameters:

  1. Input: An array of doubles and the size of the array (integer)
  2. Output: The average (double) and median (double) of the array. Use the C version of pass by reference for the output.

Inside this new function perform the following steps:

  1. Calculate the average
  2. Use a for loop to find the sum and divide by the size of the array
  3. Sort the array using either Bubble sort or Selection sort
  4. This will involve creating nested for loops AFTER you have calculated the average
  5. Don't try to both sort and calculate the average in the same loops
  6. Calculate the median
  7. The median is the middle value in a sorted array.
  8. Set the average and median pointers to the values you calculated

Back in your main function call this new function. It should take four parameters, the array, the size of the array, a pointer to an average variable and a pointer to a median variable.

Print the average and median back in the main function. Do NOT print the results in the function that did the calculation. printf should only be in your main function.

Results

If you code works you will see the following results. Note that you will not receive full credit for outputting the same numbers, but for utilizing pass by reference.


1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.