Classwork 22: Deviation from Mean

Objectives

Practice working with arrays.

The Assignment


Given a set of numbers, { x1, x2, ..., xn } the mean is the "average": ( x1 + x2 + ... + xn ) / n, where n is the number of items in the set.

The deviation from mean is the difference between an item xi and the mean. For example, for the set {3, 9, 4, 23, 17} the mean is 11.2. For the item 9, the deviation from mean is 9 − 11.2 = −2.2 and the deviation from mean for 23 is 23 − 11.2 = 11.8.

The absolute deviation from mean is just the absolute value of the deviation. Your assignment is to calculate the absolute deviation from mean for each number in the input and report the average absolute deviation from mean.

You can use the program developed in class that computes the mean (average) of the input: input4.c.

For each item in the array, your program should compute and report the value of the array item, its deviation and its absolute deviation.

A sample run of your program on this data file, data.txt, might look like the following. Note the use of input redirection to read numbers from the data file data.txt.

PT[115]% ./a.out < data.txt
The average value entered is: 36.733333
A[0] = 19,  dev = -17.733333, abs_dev = 17.733333
A[1] = 83,  dev = 46.266667, abs_dev = 46.266667
A[2] = 20,  dev = -16.733333, abs_dev = 16.733333
A[3] = 25,  dev = -11.733333, abs_dev = 11.733333
A[4] = 50,  dev = 13.266667, abs_dev = 13.266667
A[5] = 15,  dev = -21.733333, abs_dev = 21.733333
A[6] = 26,  dev = -10.733333, abs_dev = 10.733333
A[7] = 90,  dev = 53.266667, abs_dev = 53.266667
A[8] = 17,  dev = -19.733333, abs_dev = 19.733333
A[9] = 22,  dev = -14.733333, abs_dev = 14.733333
A[10] = 21,  dev = -15.733333, abs_dev = 15.733333
A[11] = 8,  dev = -28.733333, abs_dev = 28.733333
A[12] = 85,  dev = 48.266667, abs_dev = 48.266667
A[13] = 28,  dev = -8.733333, abs_dev = 8.733333
A[14] = 42,  dev = 5.266667, abs_dev = 5.266667
The average deviation from mean = 22.177778
PT[116]%

Submit

When you are done testing your program, use the script command to record a sample run of your program. Don't forget to exit from script. Then, submit your program and sample run using.

submit cs104_chang cw22 deviation.c
submit cs104_chang cw22 typescript


Be sure to logout completely when you have finished!