Shaikh Ateeque
Find the minimum and maximum element in an array in C#?
  1. public static void MaximumMinimumElementArray()
  2. {
  3. int[] array = { 10, 30, 40,100,170, 50, 20, 60 };
  4. int max = array[0];
  5. int min = array[0];
  6. for (int i=0; i<=array.Length-1; i++)
  7. {
  8. if(array[i] > max)
  9. {
  10. max = array[i];
  11. }
  12. if(array[i] < min)
  13. {
  14. min = array[i];
  15. }
  16. }
  17. Console.WriteLine(max);
  18. Console.WriteLine(min);
  19. }
By Shaikh Ateeque in .NET on Apr 08 2022
  • Jayraj Chhaya
    Sep, 2022 10

    Hi Shaikh,

    1. using System;
    2. using System.Linq;
    3. public class Example
    4. {
    5. public static void Main()
    6. {
    7. int[] arr = { 8, 3, 5, -1, 2 };
    8. Console.WriteLine("Minimum number is " + arr.Min());
    9. Console.WriteLine("Maximum number is " + arr.Max());
    10. }
    11. }

    • 2
  • Andy King
    May, 2022 5

    public static void MaxMinElementArray() {int[] array = { 10, 30, 40,100,170, 50, 20, 60 };Array.Sort(array);var last=array.Length-1;int max = array[last];int min = array[]; Console.WriteLine(max);Console.WriteLine(min); }}

    • 1
  • Vishal Yelve
    Jul, 2022 8

    static void Main(){int[] array = { 10, -10, -20, 0,15,20,30 };Console.WriteLine("Maximum Element : " +array.Max());Console.WriteLine("Minimum Element : " +array.Min());Console.Read();}

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS