Can someone help me with this question? C++ perferable Part 7- Find the median s
ID: 3593194 • Letter: C
Question
Can someone help me with this question? C++ perferable
Part 7- Find the median score In this part you will find the median item in the array. The median value of a list arranged in numerical order is the middle element of that list. However, you are not allowed to change the order of the elements or change the values in the array that you receive as a parameter. float findMedian (float array,int size) The findMedian function should take size of the array. The function should return the median of numbers in the array. e two arguments, i.e. a reference to the array and theExplanation / Answer
float findMedian(float array[], int size) {
float median;
// iterating over array
for(int i=0; i<size; i++) {
int minCount = 0;
int maxCount = 0;
// for each element , counting the number of elements greater and smaller
for(int j=0; j<size; j++){
if(array[i] >= array[j])
maxCount++;
else
minCount++;
}
int diff = maxCount - minCount;
// if difference between number of greater elements and smaller elements is 1 or -1 (in case of even size array)
// or 0 (in case of odd size array), then this is median
if(diff ==1 || diff == -1 || diff == 0){
median = array[i];
break;
}
}
return median;
}