From 843f1929ab7f562916da8979aa21d29faa46c62d Mon Sep 17 00:00:00 2001 From: Zhao Zuohong <1040110848@qq.com> Date: Tue, 24 Nov 2020 19:51:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=96=B9=E5=B7=AE=E8=AE=A1?= =?UTF-8?q?=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/_posts/answer6.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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); }