#include<iostream>
#include<cstdio>
#include<Cmath>
using namespace std;
int main(void)
{
int score[50];
int num,i;
cout<<"小组共有多少名同学? ";
cin>>num;
cout<<"请输入学生成绩:"<<endl;
for(i=0; i<num; i++)
do
{
cout<<"输入第 "<<i+1<<" 位同学的成绩:";
cin>>score[i];
}
while(score[i]<0||score[i]>100);
int max = -1,min=999,sum=0,ave;
for(i=0; i<num; i++)
{
sum+=score[i];
if(max<score[i])
{
max= score[i];
}
if(min>score[i])
{
min = score[i];
}
}
ave=sum/num;
cout<<endl<<"最高成绩为:"<<max <<",最低成绩为:"<<min<<",平均成绩为:"<<ave<<endl;
int max_num = 0, min_num =0;
for(i=0; i<num; i++)
{
if(max==score[i])
{
max_num++;
}
if(min==score[i])
{
min_num++;
}
}
cout<<"取得最高成绩"<<max<<"分的共 "<<max_num<<" 人,他们的学号是:";
for(i=0; i<num; i++)
{
if(max==score[i])
{
cout<<i+1<<" ";
}
}
cout<<endl;
cout<<"取得最低成绩"<<min<<"分的共 "<<min_num<<" 人,他们的学号是:";
for(i=0; i<num; i++)
{
if(min==score[i])
{
cout<<i<<" ";
}
}
cout<<endl;
sum = 0;
int x;
for(i=0; i<num; i++)
{
x=score[i]-ave;
sum+=x*x;
}
cout<<"标准偏差为:"<<sqrt(double(sum)/(num-1))<<endl;
return 0;
}
成绩处理
最新推荐文章于 2022-11-14 20:23:07 发布