c#方法 最大值我最小值


   static void Main(string[] args)
       {
           int[] a = { 6, 8, 9, 5, 2, 165, 58966 };
           Console.WriteLine("最大值为{0}",max(a));
            Console.WriteLine("最小值为{0}",min(a));
            Console.ReadKey();

               

       
       }
        public static int max(int[] wo) {
            int max = wo[0];
            for (int i = 0; i < wo.Length; i++) {
                if (wo[i] > max) {
                    max = wo[i];
                }
            
            }
            return max;
        
        
        
        }
        public static int min(int[] wo)
        {
            int min =wo[0];
            for (int i = 0; i < wo.Length; i++)
            {
                if (min>wo[i])
                {
                    min = wo[i];
                }

            }
            return min;



        }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM