函数数组排序带出最大最小值及平均值

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;
        }
    }
}

原文地址:https://www.cnblogs.com/lk-kk/p/4423735.html