c# 输入五个数用冒泡排序法实现由大到小的排列

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { Console.WriteLine("这是个实现由5个数组成的数组排序的程序"); int[] number =new int [5]; Console.WriteLine("请输入五个数字"); for (int i = 0; i < 5; i++) { number[i] = Convert.ToInt32( Console.ReadLine()); //number[i] = int.Parse(Console.ReadLine()); } Console.WriteLine("您输入的数字是:"); for (int i = 0; i < 5; i++) { Console.Write("{0} ",number[i]); } SortAndDisplay(number,5); Console.ReadKey(); } static void SortAndDisplay(int[] number,int n) { int temp; for (int i = 0; i < n-1; i++) { for (int j = i + 1; j < n; j++) { if (number[i] < number[j]) { temp = number[i]; number[i] = number[j]; number[j] = temp; } } } Console.WriteLine("/n该数组由大到小排序的结果是"); for (int i = 0; i < 5; i++) { Console.Write("{0} ", number[i]); } } } }

你可能感兴趣的:(C#,c#,string,class)