编程实现利用一维数组保存一门课程学生的成绩,学生成绩按由高到低排序,并输出该门课程的最高分,最低分和平均分

#include
#define M 5
void arrsort(int *a,int b);
using namespace std;
void main()
{
int a[M], x, z = 0;
for (int c = 0; c < M ; c++)
{
cin >> x;
z += x;
a[c] = x;
arrsort(a,M);
}
z /= M;
cout <<" average = " << z << endl << " min = " << a[0] << endl << " max = " << a[M-1]<< endl;
}
void arrsort(int *a,int b)
{
int c,d,e,f;
for ( c = 0; c <= b; c++)
{
e = c;
for ( d = c + 1; d < b; d++)
if (a[e] > a[c])
e = d;
if (e != c)
{
f = a[c]; a[d] = a[e]; a[e] = f;
}
}
}

你可能感兴趣的:(c++)