求教:C语言题目

来源:百度知道 编辑:UC知道 时间:2024/05/31 00:54:04
统计全班语文成绩,输入全班总成绩,求出平均成绩,可任意查询每位同学的成绩.

#include<iostream>
using namespace std;
const int N=200;
void main(){
double student[N],total=0,ave;
int k;
cout<<"Initialization the data:"<<endl;
for(k=0;k<N;k++){//以-1作为结束标志,最大输入200;
cin>>student[k];
total+=student[k];
if(student[k]==-1)
break;
}
ave=total/k;
cout<<"the average of score is: "<<ave<<endl<<endl;
cout<<"Please Input the student's num:"<<endl;
cin>>k;
k--;
cout<<"the student's score is: "<<student[k]<<endl;
return;
}