首页 > 编程语言 > 详细

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

时间:2015-04-14 01:55:52      阅读:195      评论:0      收藏:0      [点我收藏+]

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

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

原文:http://www.cnblogs.com/lk-kk/p/4423735.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!