fork download
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. // 母集団
  6. int x[] = {44, 100, 63, 99, 25, 47, 96, 42, 70, 100, 25, 80, 98, 49, 9, 46, 92, 65, 57, 50, 55, 95, 33, 7, 5, 56, 3, 25, 85, 96};
  7. int m = sizeof x / sizeof (int);
  8. int i;
  9. double u;
  10. double s2;
  11. double sum;
  12.  
  13. // 相加平均
  14. sum = 0;
  15. for (i = 0; i < m; i++) {
  16. sum += x[i];
  17. }
  18. u = sum / m;
  19.  
  20. // 母分散
  21. sum = 0;
  22. for (i = 0; i < m; i++) {
  23. sum += (u - x[i]) * (u - x[i]);
  24. }
  25. s2 = sum / m;
  26.  
  27. // 出力
  28. printf("平均値=%f\n", u);
  29. printf("分散=%f\n", s2);
  30.  
  31. return 0;
  32. }
  33.  
Success #stdin #stdout 0s 2052KB
stdin
Standard input is empty
stdout
平均値=57.233333
分散=974.645556