设学生人数N=8,提示用户输入N个人的考试成绩,然后计算出他们的平均成绩并显示出来。这个程序要怎么写啊?
#include<iostream>
using namespace std ;
const int N = 8;
float avg(int*&);
int main(){
int *student = new int[N];
int i;
for (i=0;i<N;++i){
cout<<"Please input the score of student #"<<i+1<<": ";
cin>>*(student+i);
}
cout<<"Avg: "<<avg(student)<<endl;
delete[] student;
}
float avg(int*& st){
int i;
float avg=0;
for (i=0;i<N;++i){
avg+=*(st+i);
}
return avg/N;
}