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

Median. In some situations, the median is used instead of theaverage or mean for

ID: 3618002 • Letter: M

Question

Median. In some situations, the median is used instead of theaverage or mean for measuring the center of a set of data. Supposeyou have N data, and was arranged in ascending order of magnitude.N is declared as integer.

(A) If N is odd, the median is defined as the value that occursin the middle of the set.

For example,

           2,4, 4, 6, 8, 10, 10

first: N is 7 which is an odd number.

second : the numbers are arranged in an ascedning order ofmagnitude

the median = 6 right at the middle.

(B) If N is even, the median is defined as the arithmetic meanof the two middle values. For example,

           17,17, 28, 37, 72, 81, 81, 90

first: N is 8 which is an even number.

Second: the numbers are arranged in an ascending order ofmagnitude.

The median = (37+72)/2.0 = 54.5

Write a program using an integer array to calculate the medianof a set of numbers entered by user.

The user should be able to stop the input whenever he wants tobe up to a maximum number of 20 and the program should be able tocount how many values have been entered by the user. You can usethe approach of the program ave.c in the notes of Lesson 6 forinputting data. Then find out how many data have been entered. Makesure when you enter the number, it has

to be in ascending order of magnitude.

To deal with the situation with even number, here are somesuggestions:-

(a) How do you test whether N is even?

Any number is even if it isdivisible by 2. That is remainder of the

number divided by 2 is 0.

(b) How do you get the middle two elements?

     You have find out the middle element by((N/2) - 1) which will be the

     first element, the next one will beN/2. Remember the index of the first

     element of an array is 0.

     Median = (number[(N/2)-1] +number[N/2])/2.0;

To deal with the situation with odd number, here are somesuggestions:-

(a) How do you test whether N is odd?

If an integer is not even, then itis odd.

(b) How do you get the middle element?

     

     median = (number [N/2])

Make sure your program has been run at least twice, one for oddnumber and one for even number. Appended the 2 test cases to yoursource code.

Explanation / Answer

please rate - thanks #include #include double median(int [],int); void sort(int[],int); int main() {int x[20],i=0,j,kt=0,index[10]; double average,sd,variance;        kt=0;        printf("Enter a number (-1when done) ");        scanf("%d",&x[kt]);      while(kt