// 输入10个人的分数,去掉两个最高两个最低,求平均分 Console.Write("请输入人数:"); int renshu = int.Parse(Console.ReadLine()); int[] chengji = new int[renshu]; if (renshu >= 5) { for (int h = 1; h <= renshu; h++) { Console.Write("请输入第" + h + "个人的成绩"); chengji[h - 1] = int.Parse(Console.ReadLine()); } for (int i = 0; i < renshu; i++) //冒泡排序,成绩由大到小排好 { for (int j = i; j < renshu - 1; j++) { if (chengji[i] < chengji[j + 1]) { int zhong = 0; //中间值 zhong = chengji[i]; chengji[i] = chengji[j + 1]; chengji[j + 1] = zhong; } } } int he = 0; for (int i = 0; i <= (renshu - 1); i++) //算出总的成绩 { he = he + chengji[i]; } double pj = (he - chengji[0] - chengji[1] - chengji[renshu - 2] - chengji[renshu - 1]) / (renshu - 4); Console.WriteLine("去掉两个最高分{0}、{1},去掉两个最低分{2}、{3},最后平均成绩是:{4}", chengji[0], chengji[1], chengji[renshu - 2], chengji[renshu - 1], pj); } else { Console.WriteLine("输入的人数要大于等于5!!!"); } Console.ReadKey();