如何计算 中间值 呢? Excel有个函数 Median(B1:D3)C#的 Math 方法里似乎没有呢如何计算中间值呢比如: 312,最大值是3,最小值是1,中间值2322,最大值是3,最小值是2,中间值2323,最大值是3,最小是是2,中间值3 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这样行吗List<int> list = new List<int>();list.Add(3);list.Add(1);list.Add(2);list.Sort();int min = list[0];int max = list[list.Count - 1];int middle = list[list.Count / 2]; void Main(){ test("312"); test("322"); test("323");}void test(string str){ var s=str.ToCharArray(); Console.WriteLine("Max:{0}\tMin:{1}",s.Max(),s.Min()); } excel里MEDIAN是返回给定数值组的中位数。把一组数据按大小排序,如果总数个数是奇数的话,取中间的那个数作为中位数,如果总数个数是偶数个的话,取中间那两个数的平均数作为中位数. private int GetMiddle(List<int> numArr) { int iMiddle = -1; int iCount = numArr.Count; int iIndex; if (iCount == 0) { return iMiddle; } iIndex = iCount / 2; numArr.Sort(); if (iCount % 2 == 0) { iMiddle = (numArr[iIndex] + numArr[iIndex - 1]) / 2; } else { iMiddle = numArr[iIndex]; } return iMiddle; } 如何在用API创建的窗口中添加菜单、按钮或者其他控件,求代码,下面是我的代码 C# 创建共享文件夹 文件夹查看方式 c# 关于WMI获取网络流量的问题 如果有多个键盘,全局钩子可否识别出键盘消息来自哪个键盘? 下定决心解决这个问题(项目的移植) 兄弟门我们作程序员的考个什么”认证“算是有出路了阿 我们公司很多技术员用的SQL数据库辅助工具!智能生存存储过程和SQL代码!送给大家 求C#脚本 请大家推荐一本介绍C#语法全面且有深度的书? C#树菜单的问题 贪吃蛇的那点事
List<int> list = new List<int>();
list.Add(3);
list.Add(1);
list.Add(2);list.Sort();int min = list[0];
int max = list[list.Count - 1];
int middle = list[list.Count / 2];
void Main()
{
test("312");
test("322");
test("323");
}
void test(string str)
{
var s=str.ToCharArray();
Console.WriteLine("Max:{0}\tMin:{1}",s.Max(),s.Min());
}
{
int iMiddle = -1;
int iCount = numArr.Count;
int iIndex; if (iCount == 0)
{
return iMiddle;
} iIndex = iCount / 2; numArr.Sort(); if (iCount % 2 == 0)
{
iMiddle = (numArr[iIndex] + numArr[iIndex - 1]) / 2;
}
else
{
iMiddle = numArr[iIndex];
} return iMiddle;
}