日期:2014-05-17 浏览次数:21036 次
int[] a = { 1, 16, 38, 24, 43, 55 };
int size = a.Length;
int min = int.MaxValue;
int var = 0;
int abs;
for (int i = 0; i < size - 1; i++)
{
for (int j = i + 1; j < size; j++)
{
abs = Math.Abs(a[i] - a[j]);
if (abs < min)
{
min = abs;
var = (a[i] + a[j]) / 2;
}
}
}
Console.WriteLine(var);