protected string BiJiaoDaXiao()//用C#写三个数大小排列的代码
{
int[] a = new int[3]; string b = ""; for (int i = 0; i < 3; i++)
{ a[i] = i + 1; }
//a[0] = 3; a[1] = 4; a[2] = 2;
//a[0] = 4; a[1] = 3; a[2] = 2; if (a[0] > a[1] && a[0] > a[2])
{
b += "最大数值:" + a[0].ToString();
if (a[1] > a[2]) { b += "中间数值:" + a[1].ToString() + "最小数值:" + a[2].ToString(); }
else { b += "中间数值:" + a[2].ToString() + "最小数值:" + a[1].ToString(); }
}
else if (a[1] > a[0] && a[1] > a[2])
{
b += "最大数值:" + a[1].ToString();
if (a[0] > a[2]) { b += "中间数值:" + a[0].ToString() + "最小数值:" + a[2].ToString(); }
else { b += "中间数值:" + a[2].ToString() + "最小数值:" + a[0].ToString(); }
}
else
{
if (a[1] > a[2]) { b += "最大数值:" + a[1].ToString() + "中间数值:" + a[2].ToString() + "最小数值:" + a[0].ToString(); }
else { b += "最大数值:" + a[2].ToString() + "中间数值:" + a[1].ToString() + "最小数值:" + a[0].ToString(); }
} return b;
}
int[] arry = new int[] { 20,30,4};//Array.Sort
冒泡排序:static void Main(string[] args)
{
int[] array = new int[6];
Console.WriteLine("请输入6个整形数字");
for (int i = 0; i < array.Length;i++ ) {
array[i] = int.Parse(Console.ReadLine());
}
for (int i = 0; i < array.Length - 1;i++ ) {
for (int j = 0; j < array.Length - i - 1;j++ )
{
if(array[j]>array[j+1]){
int temp = array[j + 1];
array[j + 1] = array[j];
array[j] = temp;
}
}
} Console.WriteLine("排序之后");
for (int i = 0; i < array.Length; i++)
{
Console.WriteLine(array[i]);
}
}