班上有学生若干名,已知每名学生的成绩(整数),求班上所有学生的平均成绩,保留到小数点后两位。同时输出该平均成绩整数部分四舍五入后的数值。 第一行有一个整数n(1<= n <= 100),表示学生的人数。其后n行每行有1个整数,表示每个学生的成绩,取值在int范围内。

#include<iostream>
#include<iomanip>
using namespace std ;
int main()
{
    int n;
    while(cin>>n)
    {
        int score, score_sum = 0;
        for(int i=0;i<n;i++)
        {
            cin>>score ;
            score_sum+=score;
        }
        double ave_score = (score_sum * 1.0) / n ;
        cout<<setiosflags(ios::fixed)<<setprecision(2)<<ave_score<<" ";
        int ave = (int)(ave_score) ;    // 双精度型强制转化为整形
        ave = ( (ave + 5) / 10 ) * 10 ;  //对整形进行四舍五入
        cout << ave << endl ;
    }
    return 0 ;
}

 

posted @ 2015-03-19 20:41  NYNU_ACM  阅读(9433)  评论(1编辑  收藏  举报