110,533
社区成员
发帖
与我相关
我的任务
分享
List<int> list = new List<int> { 2, 5, 8, 6, 5, 12, 8, 7, 9, 3, 7, 1, 15, 6 };
list.Sort();
list.RemoveRange(list.Count - 2, 2);
list.RemoveRange(0, 2);
double avg = list.Average();
static void Main(string[] args)
{
Console.WriteLine(GetAverage(new int[] { 2, 5, 8, 6, 5, 12, 8, 7, 9, 3, 7, 1, 15, 6 }));
}
static double GetAverage(int[] array)
{
if (array.Length > 5)
{
Array.Sort(array);
int total = 0;
for (int i = 2; i <= array.Length - 3; i++)
total += array[i];
return (double)total / (array.Length - 4);
}
return 0;
}
/*
输出6.4
*/