namespace ConsoleApplication2 { class Program { static void Main(string[] args) { try { Console.WriteLine("请输入6个数字"); int[] nums = new int[6]; for (int i = 0; i < nums.Length; i++) { Console.WriteLine("请输入第{0}个数字:", i + 1); nums[i] = Convert.ToInt32(Console.ReadLine()); } for (int i = 0; i < nums.Length - 1; i++) //比较的次数 { for (int j = 0; j < nums.Length - 1 - i; j++) //交换的次数 { if (nums[j] < nums[j+1]) { int temp = nums[j]; nums[j] = nums[j + 1]; nums[j + 1] = temp; } } } Console.Write("排序后的数字为:"); foreach (double var in nums) //遍历 { Console.Write(var); //依次读取字符串中的元素 Console.Write(" "); } } catch { Console.WriteLine("你输入的格式有误"); } Console.ReadKey(); } } }
网友评论