键盘输入的20个学生成绩,输出其最大、小值,平均分并统计其中的及格与不及格人数的C语言程序。

如题所述

第1个回答  2014-06-23
#include <stdio.h>
int main()
{

    printf("请输入学生的成绩:\n");
    int maxScore = 0;
    int minScore = 0;
    double avgScore = 0;
    int jigeCount = 0;
    int buJigeCount = 0;

    int totalScore = 0;

    int nScore;

    for(int i = 0; i < 20; i++) 
    { 
       scanf("%d", &nScore);

       if (i == 0)
       {
            maxScore = nScore;
            minScore = nScore;
       }

       if (maxScore < nScore)
       {
            maxScore = nScore;
       }

       if (minScore > nScore)
       {
           minScore = nScore;
       }

       if (nScore >= 60)
       {
           jigeCount++;
       }
       else
       {
           buJigeCount++;
       }

       totalScore += nScore;
    } 

    avgScore = (double)totalScore/20.0;
 
    printf("最高分:%d, 最低分: %d, 平均分:%0.2f\n", maxScore, minScore, avgScore);
    printf("及格人数:%d 不及格人数:%d\n", jigeCount, buJigeCount);
    return 0;
}

运行结果:

相似回答
大家正在搜