Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

No global variables. Please solve this using the sort method given within the fi

ID: 3869065 • Letter: N

Question

No global variables.
Please solve this using the sort method given within the findMedian function.

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. This will change the original array, but that's okay for this assignment. If you are testing your code by calling it from a different file, remember to have a function prototype for findMedian in that file.

Sort method:

Explanation / Answer

#include <bits/stdc++.h>
#include<iostream>
int findMedian(int *array, int size) {
std::sort(array, array + size);
for (int i = 0; i < size; i++)
     std::cout << array[i] << ' ';
if (size%2 == 1)
     return array[size/2];
return (array[size/2] + array[size/2 - 1])/2 ;

}

here you go champ!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote