C++ 编程练习:考试成绩分布统计 - 计算平均分、及格人数和不及格人数
#include "iostream"\n#include "vector"\n#include "cmath"\n#include "iomanip"\n\nusing namespace std;
\nint main() {
int n;
cin >> n;
\n vector
int sum = 0;
for (int i = 0; i < n; i++) {
cin >> scores[i];
sum += scores[i];
}
\n double avg = (double)sum / n;
int above_avg = 0;
int below_avg = 0;
\n for (int i = 0; i < n; i++) {
if (scores[i] >= avg) {
above_avg++;
} else {
below_avg++;
}
}
\n cout << fixed << setprecision(1) << avg << " " << above_avg << " " << below_avg << endl;
\n return 0;
}
原文地址: https://www.cveoy.top/t/topic/qjDk 著作权归作者所有。请勿转载和采集!