C++语言程序设计(下) 中国农业大学 单元作业10-2

题目

编写程序。模仿第10章教学课件PDF中的例10-16编写一个求平均成绩的C++程序。要求:使用C++标准库中的向量来存储若干个学生成绩,然后求其平均成绩。

答案

#include <iostream>
#include <vector>
#include <numeric>
using namespace std;
 
int main(){
    vector<int> score = {77,96,45,58,87,97};
    double avg = accumulate(score.begin(),score.end(),0.0)/score.size();
    cout << avg;
}
原创文章 63 获赞 23 访问量 2万+

猜你喜欢

转载自blog.csdn.net/qq_33384402/article/details/105878385