看视频自学到数组,做下练习出错了,求指导
int[] number ={ 13, 25, 123, 46, 684, 20, 13, 254, 16 };
int max=0,min=0,sum=0,ave=0,i=0;
for (i = 0; i <=number.Length; i++)
{
if (max < number[i])
{
max = number[i];
}
if (min > number[i])
{
min = number[i];
}
sum = sum + number[i];
}
ave = sum / number.Length;
Console.WriteLine("这个数组的最大值是{0},最小值是{1},和是{2},平均值是{3}",max,min,sum,ave);
Console.ReadKey(); |