日期:2014-05-19  浏览次数:21046 次

初学者提若智问题!
请高手帮忙解答:
用C#写一程序,键盘输入十个数,从大到小排列出来。

------解决方案--------------------
using System;

class Demo
{
static void Main()
{
int [] a = new int[10];
for(int i = 0; i < a.Length; i++)
a[i] = int.Parse(Console.ReadLine());

Array.Sort(a);
Array.Reverse(a);

foreach(int temp in a)
{
Console.Write(temp + " ");
}
}
}
------解决方案--------------------
Array.Short(new int[]{5,3,2,4});
------解决方案--------------------
using System;

class Demo
{
static void Main()
{
int [] a = new int[4];
for(int i = 0; i < a.Length; i++)
a[i] = int.Parse(Console.ReadLine());

SelectSortAscending(a);

foreach(int temp in a)
{
Console.Write(temp + " ");
}
}

public static void SelectSortAscending(int[] arr)
{
for (int i = 0; i < arr.Length - 1; i++)
{
for (int j = i + 1; j < arr.Length; j++)
{
if (arr[i] < arr[j])
{
int temp;
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
}
}