輸入n個數,n<=100,找到其中最小的數和最大的數spa
using System; namespace _1.求最大最小 { class Program { public static int GetMax(int[] numbers) { int max = numbers[0]; for (int i = 0; i < numbers.Length; i++) { if (max < numbers[i]) { max = numbers[i]; } } return max; } public static int GetMin(int[] numbers) { int min = numbers[0]; for (int i = 0; i < numbers.Length; i++) { if (min > numbers[i]) { min = numbers[i]; } } return min; } static void Main(string[] args) { string[] temp = Console.ReadLine().Split(' '); int[] numbers = new int[temp.Length]; for (int i = 0; i < temp.Length; i++) { numbers[i] = Convert.ToInt32(temp[i]); } Console.WriteLine("Max = " + GetMax(numbers)); Console.WriteLine("Min = " + GetMin(numbers)); Console.ReadKey(); } } }