#include<iostream> using namespace std; int main() { int score[50],i; double sum=0,max=-1,min=101,x=0,y=0,ave=0; double number; cout<<"请输入一共要统计的同学总人数"<<endl; cout<<"总人数为: "; cin>>number; cout<<"请输入要统计的各位同学的成绩"<<endl; for (i=0; i<number; i++) { cout<<"第"<<i+1<<"名的同学成绩是: "; cin>>score[i]; sum=score[i]+sum; } ave=sum/number; for (i=0; i<number; i++) { if (max<score[i]) max=score[i]; } for (i=0; i<number; i++) { if (min>score[i]) min=score[i]; } cout<<"统计的同学平均成绩为: "<<ave<<endl; cout<<"统计的同学最高成绩为: "<<max<<endl; cout<<"统计的同学最低成绩为: "<<min<<endl; for (i=0; i<number; i++) { if (max==score[i]) x++; } cout<<"取得最高成绩"<<max<<"分的共"<<x<<"人,"<<" "; cout<<"他们的学号是:"; for (i=0; i<number; i++) { if(score[i]==max) cout<<i+1<<" "; } for (i=0; i<number; i++) { if (min==score[i]) y++; } cout<<endl; cout<<"取得最低成绩"<<min<<"分的共"<<y<<"人,"<<" "; cout<<"他们的学号是:"; for (i=0; i<number; i++) { if(score[i]==min) cout<<i+1<<" "; } return 0; }
原文地址:http://blog.csdn.net/i__am__legend/article/details/41484251