输入人数,输入分数,求平均分,升序降序排列
ArrayList al = new ArrayList(); Console.Write("请输入班级人数:"); int n = int.Parse(Console.ReadLine()); double sum = 0; for (int i = 0; i < n; i++) { Console.Write("请输入第" + (i + 1) + "个人的分数:"); al.Add(double.Parse(Console.ReadLine())); sum += double.Parse(al[i].ToString()); } Console.WriteLine("班级平均分是:"+sum / n); al.Sort(); Console.WriteLine("成绩从低到高排列是:"); foreach(double fenshu in al) { Console.WriteLine(fenshu); } al.Reverse(); Console.WriteLine("成绩从高到低排列是:"); foreach(double fenshu in al) { Console.WriteLine(fenshu); } Console.ReadLine();