去掉两个最高分、去掉两个最低分,求平均分
static void Main47求平均分(string[] args) { //去掉两个最高分,去掉两个最低分,求平均分 Console.WriteLine("请输入分数的个数:"); int a = Convert.ToInt32(Console.ReadLine()); int [] fs = new int [a]; if (a < 5) { Console.WriteLine("输入的分数至少为5个!"); } else { for (int i = 0; i < a; i++) { Console.WriteLine("请输入第{0}个分数:",i+1); fs[i] = Convert.ToInt32(Console.ReadLine()); } //排序 for (int j = 0; j < fs.Length - 1; j++) { for (int k = 0; k < fs.Length - 1 - j; k++) { if (fs[k] <= fs[k + 1]) { int zj = fs[k]; fs[k] = fs[k + 1]; fs[k + 1] = zj; } } } //求平均分 int sum = 0; for (int x = 0; x < fs.Length; x++) { if (x == 0 || x == 1 || x == fs.Length - 1 || x == fs.Length - 2) { } else { sum = sum + fs[x]; } } int avg = sum/(fs.Length-4); Console.WriteLine("去掉两个最高分和两个最低分之后的平均数为:"+avg); } }