Description
Purpose:
- Gain experience in the mechanics of editing, compiling, and executing a C program on a linux system.
- Initial foray into C programming
Assignment:
Write a program that will calculate and display the mean, median, sum, max, and min of a provided sequence of 5 numbers.
- An array cannot be used. Global variables are OK, if you chose to use them.
- The only header you need is #include <stdio.h>
- The numbers will be hard coded as numeric literals. (clarification: for each data set below, use assignment statements to initialize the variables with the desired input data. This program requires no user input) Use the following input data:
- (25,5,0,0,2 )
- (0,0,0,0,0)
- (100,100,100,100,100)
- (1,2,3,4,5)
- (5,4,3,2,1)
- The program will be contained in a single C file.
- The program must contain the following functions:
- main
- mean
- median
- sum
- max
- min
The return types of these functions should be consistent with the result. Example; The sum of two integers is always an integer, so an ‘int’ would be the correct return value for the “sum” function.
It is acceptable for functions to be used by other functions you have written for this assignment.
- Without arrays, ‘cut and paste’ will make the size of the program large. It is permissible but not required to use additional functions or macros to minimize the lines of code you have to write.
- Please turn in only the .c file. The grader will compile and execute the program.
- Output of the program should look like this:
25 5 0 0 2
min = 0 max = 25 median = 2 sum = 32 mean = 6.400000
0 0 0 0 0
min = 0 max = 0 median = 0 sum = 0 mean = 0.000000
100 100 100 100 100
min = 100 max = 100 median = 100 sum = 500 mean = 100.000000
1 2 3 4 5
min = 1 max = 5 median = 3 sum = 15 mean = 3.000000
5 4 3 2 1
min = 1 max = 5 median = 3 sum = 15 mean = 3.000000
- For this assignment, comments are not required.
Grading Criteria:
- Program compiles and executes without warnings.
- Output values are correct.
- Compliance with assignment requirements.