qfedu-basic-level/day8/d12_2.cpp

34 lines
812 B
C++
Raw Permalink Normal View History

2023-06-23 17:31:07 +08:00
#include <iostream>
#include <cstdlib>
using namespace std;
int main(int argc, char const *argv[])
{
int score[5][4] = {
{56, 75, 78, 89},
{89, 98, 76, 67},
{88, 88, 77, 66},
{67, 78, 89, 90},
{98, 97, 96, 95}};
float avg1 = 0.0f;
float avg2 = 0.0f;
float avg3 = 0.0f;
float avg4 = 0.0f;
// 计算物理学科平均
for (int i = 0; i < 5; i++)
{
avg1 += score[i][0] / 5.0;
avg2 += score[i][1] / 5.0;
avg3 += score[i][2] / 5.0;
avg4 += score[i][3] / 5.0;
}
cout << "语文的平均成绩: " << avg1 << endl;
cout << "数学的平均成绩: " << avg2 << endl;
cout << "化学的平均成绩: " << avg3 << endl;
cout << "物理的平均成绩: " << avg4 << endl;
return 0;
}