int[] scores = { 99, 85, 74, 84, 64, 93, 91 ,87};
int temp;
for (int i = 0; i < scores.Length; i++)
{
for (int 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("排序后的成绩为:");
foreach (var item in scores)
{
Console.WriteLine("{0}\t",item.ToString());
}
网友评论