Bryjaun R.
asked 10/13/22Computer 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:
Next, create a separate function that has the following parameters:
- Input: An array of doubles and the size of the array (integer)
- 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:
- Calculate the average
- Use a for loop to find the sum and divide by the size of the array
- Sort the array using either Bubble sort or Selection sort
- This will involve creating nested for loops AFTER you have calculated the average
- Don't try to both sort and calculate the average in the same loops
- Calculate the median
- The median is the middle value in a sorted array.
- 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
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.