输入人数,输入每个人的成绩
需要最高分、最低分,
去掉两个最高分,去掉两个最低分,求平均分。
Console.Write("请输入班级人数:"); int shu = int.Parse(Console.ReadLine()); int[] fen = new int[shu]; if (shu >= 5) { for (int i = 0; i < shu; i++) { Console.Write("请输入第" + (i + 1) + "个人的成绩:"); fen[i] = int.Parse(Console.ReadLine()); } for (int i = 0; i < shu; i++) { for (int j = i; j < shu - 1; j++) { if (fen[i] < fen[j + 1]) { int zhong; zhong = fen[i]; fen[i] = fen[i + 1]; fen[i + 1] = zhong; } } } double sum = 0; Console.WriteLine("最高分为:" + fen[0] + "最低分为:" + (fen[fen.Length - 1])); for (int i = 2; i <= (fen[fen.Length - 3]); i++) { sum = fen[i]; } Console.WriteLine("平均分为:" + (sum / (shu - 4))); } else { Console.WriteLine("您输入的人数要大于等于5!"); } Console.ReadLine();
例:
抽奖活动:
输入n个手机号码,滚动号码,5秒钟后停止
输出中奖人号码
Console.Write("请输入手机号码个数:"); int a = int.Parse(Console.ReadLine()); string[] shuzu = new string[a]; for (int i = 0; i < a; i++) { Console.Write("请输入第" + (i + 1) + "个手机号码:"); shuzu[i] = Console.ReadLine(); } Console.WriteLine("所有号码输入完毕,请按回车键开始滚动号码!"); Console.ReadLine(); Random ran = new Random(); int r = 0; for (; ; ) { int aa = ran.Next(a); Console.Clear(); Console.WriteLine(shuzu[aa]); System.Threading.Thread.Sleep(100); if (r == 49) { //作弊代码 //Console.Clear(); //Console.WriteLine("110"); break; } r++; } Console.ReadLine();