Question: Write a C program in a file called median2.c and a Makefile which creates the executable median2 that calculates the median of a list of

Write a C program in a file called median2.c and a Makefile which creates the executable median2 that calculates the median of a list of numbers as described below:

Input:

The input will consist of a nonempty sequence of integers A1 A2 ... AN (N > 0) which are read from stdin. The integers are separated by whitespace and you dont know how many integers are going to be input.

Program Behavior: Your program should read in the input values, compute its median, and print this to stdout. The procedure for computing medians is described here.

Output: Since the median value may not be an integer, print out the median as a floating point value using the following statement:

printf("%.1f ", median)

Note the .1 which tells printf to print a single decimal place.

Restrictions:

The point of this problem is to get experience using malloc() or calloc() to create linked lists. Therefore you may NOT use an array where you allocate some large amount space for and for which you perhaps reallocate more space as necessary. Instead you must use a linked list to hold exactly as many integers as are input.

Errors:

If no integers are input this is an error. In this case your program should print an error message to stderr and exit with a status of 1 without printing anything to stdout. If at least one integer is input followed by something is input that cant be interpreted as an integer, your program should print an error message to stderr and then calculate and print the median of the integers that were input. Note your programs exit status should still reflect that an error was seen.

Hints:

This is like the median problem from A4 except that now we dont know how many integers are going to be input. You may reuse your code from that program, altering it to use the new data structure. Please remember the new name of this program is median2 If you leave off the 2 the grading script wont find your program.

Makefile: In addition to your source files, you should submit a make file named Makefile that supports at least the following functionality:

make median2

Compiles the C source code to create an executable named median2. The compiler options used should include -Wall.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!