Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save schauhan232/ace47c24a03cd4f84d113d801da5df24 to your computer and use it in GitHub Desktop.
Save schauhan232/ace47c24a03cd4f84d113d801da5df24 to your computer and use it in GitHub Desktop.
GeeksForGeeks: Program to find the minimum and maximum element of an array
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