In statistic, when a set of values is sorted in ascending or descending order, i
ID: 3534164 • Letter: I
Question
- In statistic, when a set of values is sorted in ascending or descending order, its median is the middle value. If the set contains an even number of values, the median is the mean, or average, of the two middle values. Write a function that accepts as arguments the following:
a) An array of integers.
The function should determine the median of the array. This value should be returned as double. (Assume the values in the array are already sorted).
b) An integer that indicates the number of elements in the array.
Demonstrate your program prowess by using pointer notation instead of array notation in this function.
- In statistic, when a set of values is sorted in ascending or descending order, its median is the middle value. If the set contains an even number of values, the median is the mean, or average, of the two middle values. Write a function that accepts as arguments the following:
a) An array of integers.
The function should determine the median of the array. This value should be returned as double. (Assume the values in the array are already sorted).
b) An integer that indicates the number of elements in the array.
Demonstrate your program prowess by using pointer notation instead of array notation in this function.
a) An array of integers.The function should determine the median of the array. This value should be returned as double. (Assume the values in the array are already sorted).
b) An integer that indicates the number of elements in the array.
Demonstrate your program prowess by using pointer notation instead of array notation in this function.
Explanation / Answer
double findMedian(int arr[], int n)
{
if(n%2==1)
return arr[n/2];
else
return ((arr[n/2-1]+arr[n/2])/2.0);
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.