Created
July 6, 2021 11:52
-
-
Save schauhan232/ace47c24a03cd4f84d113d801da5df24 to your computer and use it in GitHub Desktop.
GeeksForGeeks: Program to find the minimum and maximum element of an array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
int[] userInputArray = { 12, 1234, 45, 67, 1 }; | |
Console.WriteLine(MinimumValue(userInputArray)); | |
Console.WriteLine(MaximumValue(userInputArray)); | |
Console.Read(); | |
} | |
public static int MinimumValue(int[] input) | |
{ | |
var minimumValue = input[0]; | |
for (var i = 0; i < input.Length; i++) | |
{ | |
if (minimumValue > input[i]) | |
minimumValue = input[i]; | |
} | |
return minimumValue; | |
} | |
public static int MaximumValue(int[] input) | |
{ | |
var maximumValue = input[0]; | |
for (var i = 0; i < input.Length; i++) | |
{ | |
if (maximumValue < input[i]) | |
maximumValue = input[i]; | |
} | |
return maximumValue; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment