10个裁判打分,去掉个最高分,在去掉个最低分,最后就平均值。那10个数可以是随机产生的,也可以自己输入
来源:百度知道 编辑:UC知道 时间:2024/06/01 05:44:15
必须用C#做,需要的是代码!用C#做,急需代码,谢谢各位了,紧急问题!
我可以告诉你思路:使用随机函数产生10个随机数,既然是打分,那么可以用取模运算使产生的数在0-100之间 random(x)%101 就产生了0-100之间的数。使用数组最方便了,
编写一个max(x,y)和min(x,y)函数,使用循环求出最小和最大数去掉。或者直接把他们排序。
.net下代码如下:
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Double[] s = new Double[10];//申明数组
Random randomNo = new Random();
for(int i=0;i<10;i++)
{
s[i] = Math.Round((randomNo.NextDouble() * 100) % 101.00,2);
}
Array.Sort(s);
for (int p = 0; p < 10; p++)
Console.WriteLine(s[p]);
double all = 0;
for (int i = 1; i < 9; i++)
all = all + s[i];
all = all / 8.00;
Console.WriteLine(all);
Console.