Question: Write a function called findMedian that takes two parameters - an array of int and the size of the array. The function should return the
Write a function called findMedian that takes two parameters - an array of int and the size of the array. The function should return the median of the array, which will require sorting the array (you can use the built-in sort function from the examples). This will change the original array, but that's okay for this assignment. If you're not familiar with calculating the median, please look that up. Remember that it's different for odd and even groups of values. If you are testing your code by calling it from a different file, remember to have a function prototype for findMedian in that file.
The file must be named: findMedian.cpp.
Also, Here is the example of Sort they would like us to use.
#includeint main() { int array[] = {23, 5, -10, 0, 0, 321, 1, 2, 99, 30}; int size = 10; std::sort(array, array + size); for (int i = 0; i < size; i++) std::cout << array[i] << ' '; }
This program first initializes an array of ints. Next we use the built in sort function, which requires that you include
The median of a set of data is the middlemost number in the set. The median is also the number that is halfway into the set. To find the median, the data should be arranged in order from least to greatest. If there is an even number of items in the data set, then the median is found by taking the mean (average) of the two middlemost numbers.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
