为教师编写一个程序,该程序使用一个数组存储30个学生的考试成绩,并给各个数组元素指定一个1-100的随机值,然后计算平均成绩。
static void Main(string[] args) { int[] score = new int[30]; Random r = new Random(); //int rNumber = r.Next(1, 101); //double sum = 0.00; //for (int i = 0; i < score.Length; i++) //{ // score[i] = r.Next(1, 101); // Console.WriteLine(score[i]); // //sum += score[i]; //} Console.Write(Math.Round(AvgScore(score),2)); Console.ReadKey(); } static double AvgScore(int[] score) { Random r = new Random(); double sum = 0.00; for (int i = 0; i < score.Length; i++) { score[i] = r.Next(1, 101); sum += score[i]; } return sum / score.Length; }