评分问题

Posted on 2020-07-20 20:49  黑炽  阅读(157)  评论(0编辑  收藏  举报

得分为整数,然后去掉一个最高分和最低分,其余部分取平均值

#include<stdio.h>
#define gradeMount 10
#define LL long long

int main(void){
    int i, grade;
    int count = 0;
    LL sumGrade = 0;
    int maxGrade = -32768;//int型的最小取值
    int minGrade = 32768;
    double aveGrade = 0;

    for (i = 0; i < gradeMount; i++){
        printf("输入第%d个成绩: ", ++count);
        scanf("%d", &grade);
        sumGrade += grade;
        if (grade > maxGrade) maxGrade = grade;
        else if (grade < minGrade) minGrade = grade;
    }

    printf("去掉一个最高分  %d\n", maxGrade);
    printf("去掉一个最低分  %d\n", minGrade);

    sumGrade -= maxGrade + minGrade;
    aveGrade = sumGrade * 1.0 / (gradeMount - 2);
    printf("平均分数为  %.2lf\n", aveGrade);

    return 0;
}