录入班级数学成绩,计算最大值、平均值、不及格人数
#include<iostream>
using namespace std;
int main()
{
float a=0;
float student[100];
int i, j ,N = 0;
float max,failnum=0,sum=0;
cout << "录入学生成绩以0为结束"<<endl;
do
{
student[N] = a;
N++;
cout << "请输入第" << N << "个学生的数学成绩";
cin >> a;
} while (a!= 0);
max = student[1];
for (i = 1; i < N; i++)
{
if (max < student[i + 1])
{
max = student[i + 1];
}
}
cout <<"班级数学成绩最高分为" <<max<<endl;
for (i = 1; i < N; i++)
{
sum = sum + student[i];
}
cout << "班级数学成绩平均值为" << sum / N<<endl;
for (i = 1; i < N; i++)
{
if (student[i] < 60)
failnum++;
}
cout << "班级数学成绩不及格人数" << failnum<<endl;
return 0;
system("pause");
}