c++程序编写:输入学生成绩;统计最高分数;统计最低分数及平均成绩 程序怎么写啊越简单越好
c++
c++程序编写:输入学生成绩;统计最高分数;统计最低分数及平均成绩 程序怎么写啊越简单越好 c++
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
3条回答 默认 最新
关注#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { vector<float> scores = {99.5, 78.5, 67.5, 56.5, 45.5, 84.5, 83.5, 72.5, 91.5, 90.5}; float sum = 0, avg = 0, max = 0, min = 100; sort(scores.begin(), scores.end()); max = scores[scores.size() - 1]; min = scores[0]; for (auto score : scores) { sum += score; } avg = sum / scores.size(); cout << "The average score is: " << avg << endl; cout << "The highest score is: " << max << endl; cout << "The lowest score is: " << min << endl; cout << "The scores are: "; for (auto score : scores) { cout << score << " "; } cout << endl; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报