C++ 编程实现成绩统计:计算总分、最高分、最低分和不及格人数
#include
int main() { int n; cin >> n;
int highest = 0; // 最高分
int lowest = 300; // 最低分
int count = 0; // 总分小于180分的人数
for (int i = 0; i < n; i++) {
int score1, score2, score3;
cin >> score1 >> score2 >> score3;
int total = score1 + score2 + score3; // 计算总分
cout << i+1 << " " << total << endl; // 输出序号和总分
if (total > highest) {
highest = total; // 更新最高分
}
if (total < lowest) {
lowest = total; // 更新最低分
}
if (total < 180) {
count++; // 总分小于180分的人数加一
}
}
cout << highest << " " << lowest << " " << count << endl; // 输出最高分、最低分和总分小于180分的人数
return 0;
}
原文地址: https://www.cveoy.top/t/topic/qaG9 著作权归作者所有。请勿转载和采集!