Advertisement
Qrist

2-Dimensional Array Max and Min

Jul 5th, 2020
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.19 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Matrix
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             MatrixMethod();
  10.         }
  11.         static void MatrixMethod()
  12.         {
  13.             int[,] arr = { { 21, 19, 113, 55 }, { 33, 15, 60, 7 } };
  14.             for (int i = 0; i < arr.GetLength(0); i++)
  15.             {
  16.                 for (int j = 0; j < arr.GetLength(1); j++)
  17.                 {
  18.                     Console.Write("{0,4}", arr[i, j]);
  19.                 }
  20.                 Console.WriteLine();
  21.             }
  22.             int max = arr[0, 0];
  23.             int min = arr[0, 0];
  24.             for (int i = 0; i < arr.GetLength(0); i++)
  25.             {
  26.                 for (int j = 0; j < arr.GetLength(1); j++)
  27.                 {                
  28.  
  29.                     if (arr[i, j] > max)
  30.                     {
  31.                         max = arr[i, j];
  32.  
  33.                     }
  34.                     if (arr[i, j] < min)
  35.                     {
  36.                         min = arr[i, j];
  37.                     }
  38.                 }
  39.             }            
  40.             Console.WriteLine("Max= " + max);
  41.             Console.WriteLine("Min= " + min );          
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement