//输入10个人的分数,求最高分最低分平均分 int[] fenshu = new int[10]; int max = 0; int min = 0; int sum = 0; for (int i = 0; i < 10; i++) { fenshu[i] = int.Parse(Console.ReadLine()); sum += fenshu[i]; if (i == 0) { max = fenshu[i]; min = fenshu[i]; } else { if (max < fenshu[i]) { max = fenshu[i]; } if (min > fenshu[i]) { min = fenshu[i]; } } } Console.WriteLine("最大值:"+max); Console.WriteLine("最小值:" + min); Console.WriteLine("平均分:" + sum/10); //输入全班同学的年龄,按年龄从大到小排序 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();
时间: 2024-10-10 15:34:59