UMBC CMSC 201 & 201H Fall '98 | CSEE | 201 | 201 F'98 | lectures | news | help |
CMSC 201 Means Out: Tuesday 9/22/98 |
The objective of this assignment is to get you started writing programs in C in the UNIX environment. This project will give you practice using loops, and mixing data types.
There are three common means that can be associated with a group of values. You should already be familiar with the arithmetic mean, a.k.a. the average. The arithmetic mean is calculated by dividing the sum of all the values by the number of values.
arithMean = (val_{1} + val_{2} + val_{3} + . . . + val_{n}) / n
where each val_{i} is an individual value.
The second mean we'll work with is the geometric mean. It is calculated by taking the nth root of the product of all the values. The geometric mean is useful as a measure of central tendency, because it is less affected by extreme values then is the arithmetic mean. Here is the formula for the geometric mean.
geomMean = (val_{1} * val_{2} * val_{3} * . . . * val_{n})^{1/n}
The last mean is known as the harmonic mean. It is defined as the reciprocal of the arithmetic mean of the reciprocals. The harmonic mean is given by the formula
harmonMean = 1 / ((1/val_{1} + 1/val_{2} + 1/val_{3} + . . . + 1/val_{n}) / n )
You are to write a program that calculates each of the three means for any number of integer values the user decides to enter. You should continue to get integer values from the user until a value of 0 is entered. Your program should not accept negative values from the user and should print a suitable error message and ask for another value.
Since the calculation of the geometric mean involves the taking of the nth root of the product of the values, you will need to use the pow() function found in the math library. In order to do this, you will need to #include <math.h> so that the prototype for the pow() function can be seen before a call is made to it within your program. The math libraries are not found in the same location as the other standard libraries, so you must also tell the compiler to link in the math library. This is done by compiling using the -lm option. Here is an example:
lassie% cc proj1.c -lm
The pow() function has the following prototype:
double pow(double x, double y);
where the value returned is x ^{y}.
To submit a file called proj1.c you would type the following at the unix prompt:
submit cs201 proj1 proj1.c
Since I did not restrict the naming of your file, you may have named your file something else. The last item in the command should be the filename of the file that you wrote for your project. So if you called your file means.c, the command would be:
submit cs201 proj1 means.c
Tuesday, 06-Oct-1998 15:32:18 EDT