标签:str stat length 最大 console nbsp ++ public max
out参数:输出最大值_最小值_总和_平均值
static void Main(string[] args)
{
int[] arr = { 5, 12, -6, -9, 7, 2 };
int max;
int min;
int sum;
double avg;
GetNum(arr, out max, out min, out sum, out avg);
Console.WriteLine("最大值是:{0},最小值是:{1},总和是:{2},平均值是:{3}", max, min, sum, avg);
Console.ReadKey();
}
public static void GetNum(int[] arr, out int max, out int min, out int sum, out double avg)
{
max = arr[0];
min = arr[0];
sum = 0;
avg = 0;
for (int i = 0; i < arr.Length; i++)
{
sum += arr[i];
if (arr[i] > max)
{
max = arr[i];
}
if (arr[i] < min)
{
min = arr[i];
}
}
avg = sum * 1.0 / arr.Length;
}
标签:str stat length 最大 console nbsp ++ public max
原文地址:http://www.cnblogs.com/sky-wolf/p/7694762.html