输入5个学生的4门课的成绩,分别用函数实现下列功能 计算每个学生的平均分 将平均分从高到低排序

如题所述

#include <algorithm>
using namespace std;

//往stud数组里填充数据;avg 数组里为排好的平均分
int stud[5][4],avg[5];

bool comp(int x,int y) {
  return x>y;
}

//计算平均分
void calcuteAvg(void) {
  int tot;
  for (int i = 0; i < 5; i++) {
    tot=0;
    for (int j = 0; j < 4; j++) tot+=stud[i][j];
    avg[i]=tot/4;
  }
  sort(avg,avg+5,comp);
}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2019-05-26
平均分用average函数,排序使用rank函数。
相似回答