Question: Problem D: Averages and Medians Your task is to write a C program named D.c according to the specifications belovw Your program must read the

Problem D: Averages and Medians Your task is to write a C program named D.c according to the specifications belovw Your program must read the standard input and write to the standard output. The program will read sequences of floating-point numbers (use type double') and for each sequence print the average and median of the sequence. Each sequence is preceded with the number of elements in the se- quence. So, the program will read first the number of elements of the sequence, then all elements of the sequence, print the average and median values, and repeat this process. The program will end the first time it reads a zero or negative number as the length of the sequence. The numbers are separated by whitespace Remember that for the median you need to sort the array, and if the array has an odd number of elements the median is the element exactly in the middle; otherwise, if the array has an even number of elements, then the median is average of the two middle elements. The output numbers must be rounded to three decimals, and must follow the format descrobed below Input The input consists of several sequences of floating-point numbers. Each sequence starts with a positive integer n, followed by n floating-point numbers, all separated by whitespace. The number 0 or a negative number is at the end of input. Output For each sequence of numbers, your program must print one line in the format Avg: a Med: m where a is the sequence average, and mis the sequence median. There s exactly one space between the word Avg: and a, between a and Med: and between Med: andm. The numbers a and m must be printed with three digits precision. Sample input and output are given below: Avg: 2.250 Med: 2.000 Avg 3.667 Med: 5.000 1 4 3.0 7.0-1.0 5 0 Sample Output, with visualized whitespace Avg..2.250..Med:-2.00 Avg: 3.667 Med:-5.000
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
