记录一下学习

来源:6-8 最终项目

明月暖清风

2019-10-18 17:59

            var names = new string[] { "景珍", "林惠洋", "成蓉", "洪南昌", "龙玉民", "单江开", "田武山", "王三明" };
            var score = new int[] { 90, 65, 88, 70, 46, 81, 100, 68 };
            int sum = 0;
            int avg = 0;
            int index = 0;
            for (int x = 0; x < score.Length; x++)
            {
                sum += score[x];
            }
            avg = sum / score.Length;
            Console.WriteLine("平均分是" + avg + ",高于平均分的有:");
            for (int e = 0; e < score.Length; e++)
            {
                if (avg < score[e])
                {
                    index = e;
                }
                else
                {
                    continue;
                }
                Console.Write(names[index] + " ");
            }


写回答 关注

1回答

  • qq_慕仰2092325
    2019-10-19 16:27:07

    //学生姓名
                string[] Name = new string[] { "景珍", "林惠洋", "成蓉", "洪南昌", "龙玉民", "单江开", "田武山", "王三明" };
                int[] Score = new int[] { 90, 65, 88, 70, 46, 81, 100, 68 };
                int Sum = 0;
                foreach(int x in Score)
                {
                    Sum += x;
                }
                Sum /= Name.Length;
                Console.WriteLine("平均分是{0},高于平均分的有:",Sum);
                for (int i = 0;i<Name.Length;i++)
                {
                    if (Score[i]>Sum)
                    {
                        Console.Write(Name[i]+' ');
                    }
                }
                Console.ReadKey();



C#开发轻松入门

本门课程是C#语言的入门教程,将带你轻松入门.NET开发

254118 学习 · 1459 问题

查看课程

相似问题