标签:
比赛打分
static void Main(string[] args)
{
int[] a = new int[6];
int max = 0, min = 1000, sum = 0;
//输入
a = shuru(a);
//比较
max = Max(a);
min = Min(a);
sum = Sum(a);
//输出
shuchu(a, max, min, sum);
}
static void shuchu(int[] a, int max, int min, int sum)//输出函数式
{
double avg = 1.0 * (sum - max - min) / (a.Length - 2);
Console.WriteLine("去掉一个最高分:{0}分;去掉一个最低分:{1}分;最终得分:{2}分。", max, min, avg);
}
static int[] shuru(int[] a)//输入函数式
{
for (int i = 0; i < 6; i++)
{
Console.Write("请{0}号裁判输入选手得分:", i + 1);
a[i] = Convert.ToInt32(Console.ReadLine());
}
return a;
}
static int Max(int[] a)//比较函数式最大
{
int zd = 0;
foreach (int b in a)
{
if (b > zd)
{
zd = b;
}
}
return zd;
}
static int Min(int[] a) //比较函数式最小
{
int zx = 1000;
foreach (int b in a)
{
if (b < zx)
{
zx = b;
}
}
return zx;
}
static int Sum(int[] a)//比较函数式总和
{
int zf = 0;
foreach (int b in a)
{
zf = zf + b;
}
return zf;
}
标签:
原文地址:http://www.cnblogs.com/UC0079/p/5491763.html