using System; using System.ComponentModel.DataAnnotations; namespace ConsoleApp1 { internal class Program { public static void Main(string[] args) { int[] arr = { -10, -5, 0, 10, 20 }; MinMaxNumber(arr); } public static void MinMaxNumber(int[] numberList) { int min = numberList[0]; int max = numberList[0]; foreach (int number in numberList) { min = (number < min) ? number : min; max = (number > max) ? number : max; } Console.WriteLine("The minimum number is {0}", min); Console.WriteLine("The maximum number is {0}", max); } } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter