码迷,mamicode.com
首页 > 编程语言 > 详细

数组排序求平均

时间:2015-04-13 22:20:10      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:

 

static void Main(string[] args)

{          

  while (true)        

            {            

                        int[] al = new int[7];     

             for (int i = 0; i < al.Length; i++)    

            {      

                       Console.Write("请输入" + (i + 1) + "位同学的分数");     

                       al[i] = Convert.ToInt32(Console.ReadLine());       

             }             

             for (int j = 0; j < al.Length; j++)      

             {             

                     Console.WriteLine("请输入" + (j + 1) + "位同学的分数" + al[j] + "分");        

             }              

                     for (int i = 1; i <= al.Length - 1; i++)     

                 {               

                      for (int j = 1; j <= al.Length - i; j++)     

                      {                  

                                if (al[j] > al[j - 1])        

                           {                 

                                     int t = al[j];         

                                     al[j] = al[j - 1];              

                                    al[j - 1] = t;              

                             }         

                      }           

                }          

           for (int k = 0; k < al.Length; k++)         

         {               

                     Console.WriteLine(al[k]);        

         }              

             int x = 0;            

           for (int s = 0; s < al.Length; s++)    

         {               

                    x = x + al[s];         

         }

           Console.WriteLine("总分为" + x);       

           double n = (1.0 * x - al[0] - al[1] - al[al.Length - 1] - al[al.Length - 2]) / (al.Length - 4);       

           Console.WriteLine("平均分为:" + n);           

           Console.ReadLine();          

         }      

   }

数组排序求平均

标签:

原文地址:http://www.cnblogs.com/Mr-xue/p/4423226.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!