下面是升序得,如果要求是降序输出,稍微该下就好了
class Program
{
int[] array=new int[5];
public void paixu()
{
for (int i = 0; i < 4; i++)
{
int k,j;
k = i;
for(j=i+1;j<5;j++)
{
if (array[i] > array[j])
{
k = j;
int temp;
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
for (int i = 0; i < 5; i++)
Console.WriteLine(array[i]);
}
static void Main(string[] args)
{
Program p = new Program();
for (int i = 0; i < 5; i++)
p.array[i]=Convert.ToInt32(Console.ReadLine());
p.paixu();
Console.ReadLine();
}
}