111,094
社区成员




using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 数组
{
class Program
{
static void Main(string[] args)
{
//创建长度为10数据类型为int的数组
int[] counts = new int[10];
Random rnd = new Random();
for (int i = 0; i < counts.Length; i++)
{
counts[i] = rnd.Next(1, 101);
}
Console.WriteLine(string.Format("最大值为:{0}", Max(counts)));
Console.WriteLine(string.Format("最小值为:{0}", Min(counts)));
Console.WriteLine(string.Format("平均值为:{0}", Avg(counts)));
Console.Read();
}
public static int Max(int[] args)
{
for (int i = 0; i < args.Length-1; i++)
{
for (int j = i + 1; j < args.Length; j++)
{
if (args[i] < args[j])
{
int tmp = args[i];
args[i] = args[j];
args[j] = tmp;
}
}
}
return args[0];
}
public static int Min(int[] args)
{
for (int i = 0; i < args.Length - 1; i++)
{
for (int j = i + 1; j < args.Length; j++)
{
if (args[i] > args[j])
{
int tmp = args[i];
args[i] = args[j];
args[j] = tmp;
}
}
}
return args[0];
}
public static int Avg(int[] args)
{
int sum = 0;
for (int i = 0; i < args.Length; i++)
{
sum += args[i];
}
return sum / args.Length;
}
}
}