10个随机数排序(冒泡排序)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace _1到100内随机十个数排序
{
class Program
{
static void Main(string[] args)
{
CreatRandArray();
Console.WriteLine(" ");
CreatSortArray();
Console.Write("递增数列:" + " ");
foreach (int item in Array)
{
if (item / 10 < 1)
{ Console.Write('0' + item.ToString() + " "); }
else
{ Console.Write(item + " "); }
}
Console.ReadKey();
}
static int num;
static int max;
static int[] Array = new int[10];
private static void CreatRandArray()
{
Random rd = new Random();
for (int i = 0; i <= 9; i++)
{
num = rd.Next(1, 100);
Array[i] = num;
}
Console.Write("随机数列:" + " ");
foreach (int item in Array)
{
if (item / 10 < 1)
{ Console.Write('0' + item.ToString() + " "); }
else
{ Console.Write(item + " "); }
}
}
private static void CreatSortArray()
{
int temp;
for (int i = 0; i < Array.Length - 1; i++)
{
for (int j = i + 1; j < Array.Length; j++)
{
if (Array[i] > Array[j])
{
temp = Array[j];
Array[j] = Array[i];
Array[i] = temp;
}
}
}
}
}
}