32 lines
768 B
C++
32 lines
768 B
C++
// 计算某一个学科的平均成绩
|
|
#include <iostream>
|
|
#include <cstdlib>
|
|
|
|
using namespace std;
|
|
|
|
int main()
|
|
{
|
|
int score[5][4] = {
|
|
{56, 75, 78, 89},
|
|
{89, 98, 76, 67},
|
|
{88, 88, 77, 66},
|
|
{67, 78, 89, 90},
|
|
{98, 97, 96, 95}};
|
|
|
|
string subject[] = {"语文", "数学", "化学", "物理"};
|
|
|
|
float avg = 0.0f;
|
|
// 每个人的平均成绩
|
|
for (int j = 0; j < 4; j++)
|
|
{
|
|
avg = 0.0f; // 重置平均成绩, 目的: 避免上一次的平均成绩影响到这一次的平均成绩
|
|
for (int i = 0; i < 5; i++)
|
|
{
|
|
|
|
avg += score[i][j] / 5.0f; // 求出某一个学科的平均成绩
|
|
}
|
|
cout << subject[j] << "的平均成绩: " << avg << endl;
|
|
}
|
|
|
|
return 0;
|
|
} |