Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a C Program Your program must read the standard input and write to the standard output. The program will read sequences of floating-point numbers
Write a C Program 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 The input consists of several sequences of floating-poin 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 m is the sequence median. There is exactly one space between the word Avg: and a, between a and Med: and between Med: and m. The numbers a and m must be printed with three digits precision. Sample input and output are given below: Sample Input Sample Output Avg: 2.250 Med: 2.000 Avg: 3.667 Med: 5.000 1 4 3.0 Sample Output, with visualized whitespace Avg: -2.250 Med:2.00 Avg:3.667 Med: 5.000 Note: is a space, and ] is a newline character The program must be implemented the following way: To calculate the median value, you should read numbers of a sequence in an array and sort them. You should declare the array after reading the sequence length, or you can assume that the array is at most 100 elements long and just declare an array of 100 elements. You must sort the array using the MergeSort algorithm. For this you must declare two functions that should be named merge_sort and merge or you can use similar names
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started