一个整型数组的平均:
1 class Program 2 { 3 static void Main(string[] args) 4 { 5 int[] array = {1,2,3,4,5,6,7,8,9,10}; 6 double avg= GetAvg(array); 7 Console.WriteLine("数组的平均值是:{0}",avg); 8 Console.ReadKey(); 9 } 10 /// <summary> 11 /// 求数组的平均值 12 /// </summary> 13 /// <param name="array"></param> 14 /// <returns></returns> 15 private static double GetAvg(int[] array) 16 { 17 double sum = 0; 18 for (int i = 0; i < array.Length; i++) 19 { 20 sum += array[i]; 21 } 22 double avg = sum/array.Length; 23 return avg; 24 } 25 }