得到一组数据,去掉一到两个最大数,和一到两个最小数,再求平均值,有什么该当比较准确点取平均值的么? 如2,5,8,6,5,12,8,7,9,3,7,1,15,6 去掉最小数,1,2 去掉最大数,12,15 再求剩下的平均值,能用一个函数比较快速地算出么? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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*/ 不是,这组数据是在一个object的items里,比如object.items[i].x=10 添加到Arrylist里边在sort 一样 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(); C#.NET 用FtpWebRequest 方式连接FTP服务器 问题 js Eval传参问题 菜鸟新手将暴死深圳街头 如何在BackgroundWorker Dowork进行并行数据处理 C#正则高手帮忙!!! c#抽象类内是否要有方法的实现? c# 在应用程序运行时 怎样隐藏鼠标呀 各位老师 帮帮忙被~~~~ 求助C#的文本文件操作! Gif动画如何生成? 问题 关于 wpf 3D 显示透明问题, 达人指教!(前面一个帖子有问题,Sorry!) C# WinForm 做个像瑞星的卡卡助手(就是那个爱打呼的小狮子) 有人做过么?
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
*/
list.Sort();
list.RemoveRange(list.Count - 2, 2);
list.RemoveRange(0, 2);
double avg = list.Average();