1 /**** 2 * 3 * This program computes simple statistics for five real numbers read from 4 * standard input. The statistics computed are the sum of the numbers, the 5 * arithmetic mean, and the standard deviation. The results are output to 6 * standard output, in the following form: 7 * 8 * Sum = 9 * Mean = 10 * Standard Deviation = 11 * 12 * Author: Gene Fisher (gfisher@calpoly.edu) 13 * Created: 31mar11 14 * Last Modified: 31mar11 15 * 16 */ 17 18 #include 19 #include 20 21 #define NUM_DATA_POINTS 5 /* Fixed number of data points */ 22 23 int main () { 24 25 double x1, x2, x3, x4, x5; /* Input variables */ 26 double sum; /* Computed sum */ 27 double mean; /* Computed mean */ 28 double std_dev; /* Computed standard deviation */ 29 30 /* 31 * Prompt the user for the input. 32 */ 33 printf("Enter five real numbers, separated by spaces: "); 34 35 /* 36 * Input the numbers. 37 */ 38 scanf("%lf%lf%lf%lf%lf", &x1, &x2, &x3, &x4, &x5); 39 40 /* 41 * Compute the sum. 42 */ 43 sum = x1 + x2 + x3 + x4 + x5; 44 45 /* 46 * Compute the mean. 47 */ 48 mean = sum / NUM_DATA_POINTS; 49 50 /* 51 * Compute the standard deviation. 52 */ 53 std_dev = sqrt((pow(x1 - mean, 2) + 54 pow(x2 - mean, 2) + 55 pow(x3 - mean, 2) + 56 pow(x4 - mean, 2) + 57 pow(x5 - mean, 2)) / (NUM_DATA_POINTS - 1 )); 58 59 /* 60 * Output the results. 61 */ 62 printf("Sum = %f\n", sum); 63 printf("Mean = %f\n", mean); 64 printf("Standard Deviation = %f\n\n", std_dev); 65 66 return 0; 67 68 }