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
  • Vishal Yelve
    Jul, 2022 8

    • 0
  • 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); }}

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS