设学生人数N=8,提示用户输入N个人的考试成绩,然后计算出他们的平均成绩显示出来

要求是c++用动态数组和平均成绩用函数来表示

#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;

}
温馨提示:答案为网友推荐,仅供参考