static void Main(string[] args)
{
int[] nums = { 2,3,4,1,6,5};
int sum, max, min;
sum = Compute(nums, out max, out min);
Console.WriteLine("数组的和为:{0} 最大值为:{1} 最小值为:{2}",sum,max,min);
Console.ReadKey();
}
//写一个方法,返回和,最大值,最小值
public static int Compute(int[] numbers,out int max,out int min)
{
int sum = 0;
max=0;
min=0;
for (int i = 0; i < numbers.Length; i++)
{
sum+=numbers;
if (numbers > max)
{
max=numbers;
}
if (numbers < min)
{
min=numbers;
}
}
return sum;
}
|