日期:2014-05-18 浏览次数:20808 次
int[] nums = new int[10]; for (int i = 0; i < 10; i++) { System.Console.WriteLine("请输入第{0}个数:", i + 1); nums[i] = System.Int32.Parse(System.Console.ReadLine()); }//输入10个数 for (int k = 0; k < 10; k++) { int temp = nums[k]; for (int i = k + 1; i < 10; i++) { if (temp > nums[i]) { temp = nums[i]; nums[i] = nums[k]; nums[k] = temp; } } } System.Console.WriteLine();//空行 for (int j = 0; j < 10; j++) { System.Console.WriteLine(nums[j]); }
int[] NumArry = {10,11,3,4,5,6,7,8,2,12}; //求最大 for (int i = 1; i < NumArry.Length; i++) { int maxNum = NumArry[0]; if (NumArry[i] > maxNum) //循环判断大于 maxNum = NumArry[i]; } Console.WriteLine(maxNum); //求最小 for (int i = 1; i < NumArry.Length; i++) { int minNum = intArr[0]; if (NumArry[i] < minNum) //循环判断小于 minNum = NumArry[i]; } Console.WriteLine(minNum);