static void Main(string[] args)
{ int[] scores = new int[5]; int i,j; int temp; Console.WriteLine("请输入5个学员的成绩:"); for (i = 0; i < 5; i++) { Console.WriteLine("请输入第{0}个学员的成绩",i + 1); scores[i] = int.Parse(Console.ReadLine()); }for (i = 0; i < scores.Length -1; i++)
{ for (j = 0; j < scores.Length -1 - i; j++) { if (scores[j] > scores[j+1]) { temp = scores[j]; scores[j] = scores[j+1]; scores[j + 1] = temp; } } } Console.WriteLine("排序后:"); for (i = 0; i < scores.Length; i++) { Console.WriteLine("{0}\t",scores[i]); } Console.ReadLine(); }口诀(升序):
N个数字来排序,两两相比小靠前
外层循环 I-1,内存循环 I-1-J
如果要降序,只把大于换小于