C++成绩统计程序:计算总分、最高分、最低分和低于180分的学生人数
#include
int main() { int n; cin >> n; // 输入参加考试的人数
int max_score = 0; // 最高分
int min_score = INT_MAX; // 最低分
int count = 0; // 总分小于180分的人数
for (int i = 1; i <= n; i++) {
int score1, score2, score3;
cin >> score1 >> score2 >> score3; // 输入三科成绩
int total_score = score1 + score2 + score3; // 计算总分
cout << i << " " << total_score << endl; // 输出序号和总分
if (total_score > max_score) { // 更新最高分
max_score = total_score;
}
if (total_score < min_score) { // 更新最低分
min_score = total_score;
}
if (total_score < 180) { // 统计总分小于180分的人数
count++;
}
}
cout << max_score << " " << min_score << " " << count << endl; // 输出最高分、最低分和总分小于180分的人数
return 0;
}
原文地址: https://www.cveoy.top/t/topic/qaG3 著作权归作者所有。请勿转载和采集!