diff --git a/source/_posts/answer6.md b/source/_posts/answer6.md index 8d0d546..1d1dda3 100644 --- a/source/_posts/answer6.md +++ b/source/_posts/answer6.md @@ -195,6 +195,7 @@ int main() #include 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); }