#include <iostream>
using namespace std;
int input(float ar [],int n);
void show(float ar[],int n);
float aver(float ar[],int n);
int main() {
float score[10];
int m=input(score,10);
show(score,m);
cout<<"The average is : "<<aver(score,m)<<endl;
return 0;
}
int input(float ar [],int n)
{
cout<<"Input ten scores:(q to quit):"<<endl;
int i=0;
while(i<10&&cin>>ar[i])
++i;
return i;
}
void show(float ar[],int n)
{
cout<<"Scores:"<<endl;
for(int i=0;i<n;++i)
cout<<ar[i]<<' ';
cout<<endl;
}
float aver(float ar[],int n)
{
float sum=0;
for(int i=0;i<n;++i)
sum+=ar[i];
return sum/n;
}
C++primer plus 6th 第7章7.2编程答案
最新推荐文章于 2024-08-21 18:16:36 发布