提交时间:2026-03-06 14:59:57
运行 ID: 85102
#include <iostream> #include <iomanip> using namespace std; int main() { const int STUDENTS = 3; const int SUBJECTS = 2; // 创建二维数组存储学生成绩 int scores[STUDENTS][SUBJECTS]; // 输入学生成绩 for (int i = 0; i < STUDENTS; i++) { for (int j = 0; j < SUBJECTS; j++) { cin >> scores[i][j]; } } // 计算并输出每个学生的总分 for (int i = 0; i < STUDENTS; i++) { int total = 0; for (int j = 0; j < SUBJECTS; j++) { total += scores[i][j]; } cout << total; if (i < STUDENTS - 1) { cout << " "; } } cout << endl; // 计算并输出每门科目的平均分(向下取整) for (int j = 0; j < SUBJECTS; j++) { int subjectTotal = 0; for (int i = 0; i < STUDENTS; i++) { subjectTotal += scores[i][j]; } int average = subjectTotal / STUDENTS; cout << average; if (j < SUBJECTS - 1) { cout << " "; } } cout << endl; return 0; }