Write a function called median, that takes as parameter a full, sorted array of doubles and returns the median of the list. For a sorted list of odd length, the median is the middle value. For a sorted list of even length, the median is the average of the two middle values. Make an example function call in your main.

Answer :

Answer: Provided in the explanation section

Explanation:

#include <stdio.h>

double median(double array[] , int n)

{

double med;

//if n is even then return average of middle of two element.

if(n%2==0)

med = ( array[(n-1)/2] + array[n/2] ) /2.0 ;

else

med = array[n/2];//if n is odd return middle element.

 

return (med);

}

int main()

{

double array[6] = {1.3,3.5,5,7.7,9.0,11};

//size store size of array.

int size=sizeof(array)/sizeof(double);

//call the median function.

double medvalue =median(array, size);

printf("median is : %lf\n",medvalue);

return 0;

}

//OUTPUT : median is : 6.350000

⇒ Provided is the Image of the code and output.

cheers i hope this helped !!

${teks-lihat-gambar} Preciousorekha1

Other Questions