标签:
输入同学的分数,去掉两个最高分,去掉两个最低分,求和后取平均分
Console.Write("请输入人数:"); int r = Convert.ToInt32(Console.ReadLine()); int[] cj = new int[r]; if (r >= 5) { for (int i = 0; i < r; i++) { Console.WriteLine("请输入第{0}个人的成绩", i + 1); cj[i] = Convert.ToInt32(Console.ReadLine()); } for (int a = 0; a < cj.Length - 1; a++) { for (int b = 0; b < cj.Length - 1 - a; b++) { if (cj[b] >= cj[b + 1]) { int zj = cj[b]; cj[b] = cj[b + 1]; cj[b + 1] = zj; } } } int sum = 0; for (int x = 0; x < cj.Length; x++) { if (x == 0 || x == 1 || x == cj.Length - 1 || x == cj.Length - 2) { } else { sum = sum + cj[x]; } } double pj = sum / (cj.Length - 4); Console.WriteLine("去掉两个最高分两个最低分之后的平均数为:" + pj); } else { Console.WriteLine("请输入的人数大于等于5!!!"); }
标签:
原文地址:http://www.cnblogs.com/jia520110270/p/4649796.html