您的位置:首页 > 其它

从键盘输入若干个同学的成绩,统计并输出最高成绩 最低成绩 平均分,当输入负数时结束输入

2012-04-13 11:44 2451 查看
算法:

#include<iostream>
using namespace std;
int main()
{
float ave,score,max,min,sum=0;
int n=0;   cin>>score;
max=min=score;
while(score>=0)
{
sum=sum+score;
n++;
cin>>score;
ave=sum/n;
if(score<0) break;
if(max<score)
max=score;
if(min>score)
min=score;
}
cout<<"ave="<<ave<<endl;
cout<<"max="<<max<<endl;
cout<<"min="<<min<<endl;
return 0;
}


运行结果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐