排序方法:去掉最高最低分求平均分 函数

法1

namespace
函数数组排序带出最大最小值及平均值 { class Program { static void Main(string[] args) { int[] b=new int[]{9,1,5,3,7}; int max = 0; //设置两个变量用来接收最低值与最小值。 int min = 0; int ave = 0; //设变一个变量来接收平均值。 int[]a= new Program().Array(b,out max,out min,out ave); for (int i = 0; i < b.Length; i++) { Console.WriteLine( b[i]); } Console.WriteLine("最大值"+max); Console.WriteLine("最小值"+min); Console.WriteLine("平均值"+ave); Console.ReadLine(); } public int[] Array(int[]a,out int x,out int y,out int ave) //跳出x,y和ave三个变量,返回int[]a变量。 { int temp = 0; for (int i = 1; i <= a.Length; i++) { for (int j = 1; j <= a.Length-i; j++) { if(a[j-1]<a[j]) { temp = a[j - 1]; a[j - 1] = a[j]; a[j] = temp; } } } x = a[0]; //最大值 y=a[a.Length-1]; //最小值 int sum = 0; for (int i = 0; i < a.Length; i++) { sum = sum + a[i]; } ave = sum / (a.Length); return a; } } }

法2
namespace ConsoleApplication10
{
    class Program
    {    
        public double[] paixu(double[] a)
        {
            double temp;
            for (int i = 0; i < a.Length; i++)//位数循环 快速排序
            {
                for (int j = i; j < a.Length - 1; j++)//位数与后面的比较
                {
                    if (a[i] < a[j + 1])
                    {
                        temp = a[i];
                        a[i] = a[j + 1];
                        a[j + 1] = temp;
                    }
                }
            }
            return a;
        }
        static void Main(string[] args)
        {
            Console.BackgroundColor = ConsoleColor.White;
            Console.Clear();
            double[] a = new double[5];
            double sum = 0;
            for (int i = 0; i < a.Length; i++)
            {
                a[i] = Convert.ToInt32(Console.ReadLine());
                sum = sum + a[i];
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("" + (i + 1) + "个评委的分数为" + a[i]);
            }
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("总分为"+sum);

            double[] b = new Program().paixu(a);
            for (int i = 0; i <a.Length; i++)
            {
                Console.WriteLine(a[i]);
            }
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("最高分" + a[0]);
            Console.WriteLine("最低分" + a[4]);
            double pj = (sum - a[0] - a[4])/(a.Length-2);
            Console.WriteLine("去掉一个最高分和最低分之后的平均最后得分为" + pj);  
            Console.ReadLine();
        }
    }
}
 
  

 

 

 

转载于:https://www.cnblogs.com/dlexia/p/4439436.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值