在这里给出一组输入。例如: 3 1 2 3 输出样例: 在这里给出相应的输出。例如: 1 2 3用c++实现
时间: 2024-03-16 13:45:15 浏览: 25
好的,以下是用C++实现的代码:
```cpp
#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;
void calculate_average(vector<vector<double>>& scores) {
int m = scores.size();
int n = scores[0].size();
for (int i = 0; i < m; i++) {
double sum = 0;
for (int j = 0; j < n; j++) {
sum += scores[i][j];
cout << fixed << setprecision(2) << scores[i][j] << " ";
}
double avg = sum / n;
cout << "Average: " << fixed << setprecision(2) << avg << endl;
}
}
int main() {
int m, n;
cin >> m >> n;
vector<vector<double>> scores(m, vector<double>(n));
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
cin >> scores[i][j];
}
}
calculate_average(scores);
return 0;
}
```
这个程序首先读入输入数据中的m和n,然后创建一个二维vector scores,用来存储每个学生的成绩。接下来循环读入每个学生的成绩,并将成绩存入scores中。最后调用calculate_average函数计算平均分并输出。
希望这个实现能够帮助到你。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)