标签:交换变量 int using 定义 数值 变量 string console read
using System;
namespace sort
{
class MainClass
{
public static void Main (string[] args)
{
int [] sum=new int [5]{0,5,6,8,21};
for (int i = 0; i <sum.Length-1; i++)//总共要比较的趟数
{
for (int j =0; j < sum.Length-1-i; j++) //每趟要比较的次数
{
if(sum[j]<sum[j+1]) //判断两个数值的大小,若前面数比后面数值小,两个数交换位置
{
int team = sum[j];//定义交换变量
sum[j] = sum[j + 1];
sum[j+1]=team;
}
}
}
Console.Write("排序之后的数是:");//遍历数组
for (int i = 0; i < sum.Length; i++){
Console.WriteLine (sum[i]+""); }
Console.ReadKey ();
}
}
}
标签:交换变量 int using 定义 数值 变量 string console read
原文地址:http://www.cnblogs.com/JL1996/p/7674245.html