c#编写一个学生成绩计算程序,统计出一个班学生的某门课程各分数段的人数(分数段:90分以上,80-90,70-80,

1个回答

  • int[] score = new int[10]; string[] m = { };

    int i, a, b, c, d, e;

    a = b = c = d = e = 0;

    double t = 0, max, min, r;

    Console.WriteLine("请输入20名学生的成绩 以回车符区分");

    for (i = 0; i < 10; i++)

    {

    int inputScore = 0;

    if (!int.TryParse(Console.ReadLine(), out inputScore))

    {

    Console.WriteLine("请输入数字类型成绩");

    i--;

    }

    score[i] = inputScore;

    }

    for (i = 0; i < 10; i++)

    {

    switch (score[i] / 10)

    {

    case 10:

    case 9: a++; break;

    case 8: b++; break;

    case 7: c++; break;

    case 6: d++; break;

    default: e++;

    break;

    }

    }

    max = score[0];

    min = score[0];

    for (i = 0; i < 10; i++)

    {

    t += score[i];

    if (score[i] > max) max = score[i];

    if (score[i] < min) min = score[i];

    }

    r = t / 10;

    Console.WriteLine("平均分为:{0}", r);

    Console.WriteLine("最高分为:{0}", max);

    Console.WriteLine("最低分为:{0}", min);

    Console.WriteLine("得优人数 :{0}", a);

    Console.WriteLine("得良人数 : {0}", b);

    Console.WriteLine("得好人数 :{0}", c);

    Console.WriteLine("及格人数 :{0}", d);

    Console.WriteLine("不及格人数 :{0}", e);

    Console.ReadLine();