C++ 急用,跪谢大神 有一个一维数组,内放n个学生成绩,输出各分数段人数,平均分,最

2025-02-24 18:16:09
推荐回答(1个)
回答1:

#include
using namespace std;
void main()
{

int a[10] = {60, 70, 80, 90, 66, 77, 88, 99, 100, 89};

int count[11] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; int max = a[0];

int min = a[0];
int i;

double avg = a[0];
for (i = 1; i < 10; i++)

{

if (max < a[i])

{ max = a[i]; }

if (min > a[i])

{ min = a[i]; }
avg += a[i];

count[a[i] / 10]++;
}

avg /= 10;
cout << "最高分:" << max << endl;
cout << "最低分:" << min << endl; cout << "平均分:" << avg << endl;

for (i = 0; i < 10; i++)

{
cout << 10 * i << "~" << 10 * i + 9 << "人数:" << count[i] << endl;
}
cout << 100 << "人数:" << count[i] << endl;
}