luc060.c (907B)
1 /* For the following set of sample data, compute the standard deviation and the mean.\nData: -6, -12, 8, 13, 11, 6, 7, 2, -6, -9, -10, 11, 10, 9, 2 2 */ 3 4 /* Let Us C, Chap- 13 (Arrays), Qn No.: B(f) */ 5 6 /* This file is auto-generated by a bot. */ 7 /* This code is not compiled; it is for reference only. */ 8 9 10 #include <stdio.h> 11 #include <math.h> 12 #include <stdlib.h> 13 14 int main() 15 { 16 int data[] = {-6, -12, 8, 13, 11, 6, 7, 2, -6, -9, -10, 11, 10, 9, 2}; 17 int n = 15, i; 18 double sum = 0.0, mean, std_dev = 0.0; 19 20 // Calculate Mean 21 for (i = 0; i < n; i++) 22 { 23 sum += data[i]; 24 } 25 mean = sum / n; 26 27 // Calculate Standard Deviation 28 for (i = 0; i < n; i++) 29 { 30 std_dev += pow(data[i] - mean, 2); 31 } 32 std_dev = sqrt(std_dev / n); 33 34 printf("Count: %d\n", n); 35 printf("Mean: %.2f\n", mean); 36 printf("Standard Deviation: %.2f\n", std_dev); 37 38 return 0; 39 }