输入整型数组和N,返回数组每N个平均后新数组

 
        private ArrayList GetAvg(int[] arr, int n)
        {
            ArrayList arrAvg 
= new ArrayList();

            
for (int i = 0; i < arr.Length; i += n)
            {
                
int x = 0;
                
for (int j = 0; j < n; j++)
                {
                    
if (i + j == arr.Length - 1 && j < n - 1)
                    {
                        n 
= j + 1;
                    }
                    x 
+= arr[i + j];
                }
                x 
/= n;
                arrAvg.Add(x);
            }
            return arrAvg;
        }
原文地址:https://www.cnblogs.com/bloodofhero/p/1723607.html