修正方差计算

This commit is contained in:
zhbaor 2020-11-24 19:51:19 +08:00
parent f9992eecc9
commit 843f1929ab

View file

@ -195,6 +195,7 @@ int main()
#include <stdio.h>
double score[5][3];
double average[5];
void Average_Student(void)
{
@ -204,6 +205,7 @@ void Average_Student(void)
avg += score[i][j];
}
avg /= 3;
average[i] = avg;
printf("第%d个学生的平均成绩是%f\n", i + 1, avg);
}
}
@ -240,13 +242,11 @@ void Calc_Var(void)
{
double sum_xi = 0;
double sum_xi2 = 0;
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 5; ++j) {
sum_xi2 += score[i][j];
sum_xi2 += score[i][j] * score[i][j];
}
for (int i = 0; i < 5; ++i) {
sum_xi += average[i];
sum_xi2 += average[i] * average[i];
}
double sigma = sum_xi2 / 15 - sum_xi * sum_xi / 225;
double sigma = sum_xi2 / 5 - sum_xi * sum_xi / 25;
printf("方差是%f\n", sigma);
}