C#选择结构从大到小排列十个数

来源:百度知道 编辑:UC知道 时间:2024/06/25 01:05:25
定义一个大小为10的整型数组,用随机产生的数据为数组元素赋值,并将它们按从大到小排序输出(使用选择法进行排序)

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int[] a = new int[10];
Random ran=new Random();
for (int i = 0; i < 10; i++)
{
int b = ran.Next(1, 100);
a[i] = b;
}
Array.Sort(a);
for (int j = 9; j >=0; j--)
{
Console.WriteLine(a[j]);
}
}
}
}

程序已调试过了。。可行。