问答详情
源自:6-8 最终项目

记录一下学习

            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] + " ");
            }


提问者:明月暖清风 2019-10-18 17:59

个回答

  • 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();