编写一个C++程序,输入十名学生的十科成绩,计算所有成绩的最大值和最小值,及平均成绩。

如题所述

#include"head.h"

#include <bits/stdc++.h>
using namespace std;
struct stu
{
    int socol[10];
};
int main()
{
    srand(unsigned(time(NULL)));
    stu s[10];
    int max1=0,min1=0;
    double sum=0;
    for(int i=0;i<10;++i)
    {
        int totol=0;
        for(int j=0;j<10;++j)
        {
            s[i].socol[j] = rand()%100;
            sum+=s[i].socol[j];
            totol+=s[i].socol[j];
        }
        max1=max(totol,max1);
        min1=min(totol,max1);
    }
    cout << "总成绩最多的是" << max1 << "分"<<endl;
    cout << "总成绩最少的是" << min1 << "分"<<endl;
    cout << "平均分是" << sum/10 << "分"<<endl;
    return 0;
}

温馨提示:答案为网友推荐,仅供参考
相似回答