int sum = 0;
int[] ary = new int[] { 1, 2, 3,10, 4, 6, 9 };
for (int i = 0; i < ary.Length / 2; i++)
{
sum += ary[i];
sum += ary[ary.Length - i - 1];
}
if (ary.Length % 2 != 0)
{
sum += ary[ary.Length / 2 ];
}
int avg = sum / ary.Length;
this.TextBox1.Text = avg.ToString();
减少循环次数! |