计算一个班5个学生的平均成绩,然后输出低于平均成绩的分数和人数
#include<iostream>
using namespace std;
int main()
{
float ave,score[5];
float sum=0;
int i,count;
cout<<"Please input 5 student's score:"<<endl;
for(i=0;i<5;i++)
cin>>score[i];
for(i=0;i<5;i++)
sum+=score[i];
ave=sum/5;
cout<<"average="<<ave<<endl;
cout<<"the score below the average:";
count=0;
for(i=0;i<5;i++)
if(score[i]<ave)
{
cout<<score[i]<<" ";
count++;
}
cout<<endl;
cout<<"the number which are below the average:";
cout<<count;
return 0;
}
网友评论