o9.15冒泡排序
//输入全班同学的年龄,按年龄从大到小排序 Console.Write("请输入人数:"); int n = int.Parse(Console.ReadLine()); int[] nianling = new int[n]; for (int i = 0; i < n; i++) { Console.Write("请输入第{0}个人的年龄:",i+1); nianling[i] = int.Parse(Console.ReadLine()); } //开始排序 for (int j = 0; j < n - 1; j++) { for (int i = j+1; i < n; i++) { if (nianling[i] > nianling[j]) { //等量代换 int zhong = nianling[i]; nianling[i] = nianling[j]; nianling[j] = zhong; } } } foreach (int i in nianling) { Console.WriteLine(i); } Console.ReadLine();