1 求和、平均分、最值 2 using System; 3 using System.Collections.Generic; 4 using System.Text; 5 6 namespace ChenJiTongJi 7 { 8 class Program 9 { 10 static void Main(string[] args) 11 { 12 Console.Write("请输入学生个数:"); 13 int n = Convert.ToInt32(Console.ReadLine()); 14 15 Console.Write("请输入总分值:"); 16 double zongfenzhi = Convert.ToInt32(Console.ReadLine()); 17 18 double[] chengji = new double[n]; 19 for (int i = 0; i < n; i++) 20 { 21 int a = i + 1; 22 Console.Write("请输入第" + a + "个成绩:"); 23 chengji[i] = Convert.ToDouble(Console.ReadLine()); 24 } 25 26 //求最好成绩(最大值) 27 28 double max = 0; 29 for (int j = 0; j < chengji.Length; j++) 30 { 31 if (chengji[j] > max) 32 { 33 max = chengji[j]; 34 } 35 } 36 37 //求最小成绩(最小值) 38 39 double min = zongfenzhi; 40 for (int x = 0; x < chengji.Length; x++) 41 { 42 if (chengji[x] < min) 43 { 44 min = chengji[x]; 45 } 46 } 47 48 //求总分、平均分 49 50 double zongfen = 0; 51 for (int m = 0; m < chengji.Length; m++) 52 { 53 zongfen += chengji[m]; 54 } 55 double pingjunfen = zongfen / n; 56 57 Console.WriteLine("最差成绩为" + min); 58 Console.WriteLine("最好成绩为" + max); 59 Console.WriteLine("总分为" + zongfen); 60 Console.WriteLine("平均分为" + pingjunfen); 61 62 Console.ReadLine(); 63 } 64 } 65 }