Skip to content
On this page

最终项目

下面是一些同学的姓名和对应的考试分数,请输出他们的平均分和高于平均分的同学姓名。

姓名景珍林惠洋成蓉洪南昌龙玉民单江开田武山王三明
分数90658870468110068

运行效果如下:

bash
平均分是76,高于平均分的有:
景珍 成蓉 单江开 田武山

代码

csharp
using System;

namespace projAboveAvg
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] names = new string[] {"景珍", "林惠洋", "成蓉", "洪南昌", "龙玉民", "单江开", "田武山", "王三明"};
            int[] scores = new int[] { 90, 65, 88, 70, 46, 81, 100, 68 };

            int sum = 0;
            for (int i = 0; i < scores.Length; ++i) {
                sum += scores[i];
            }
            int average = sum / scores.Length;
            Console.Write($"平均分是{average},");

            Console.WriteLine("高于平均分的有:");
            for (int i = 0; i < scores.Length; ++i) {
                if (scores[i] > average) {
                    Console.Write($"{names[i]} ");
                }
            }
        }
    }
}