Askor

Hw16

Jul 2nd, 2020 (edited)
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.58 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Test
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int[,] array = new int[10,10];
  10.             Random rand = new Random();
  11.             int maxElement = int.MinValue;
  12.  
  13.             for(int i = 0; i < array.GetLength(0); i++)
  14.             {
  15.                 for(int j = 0; j < array.GetLength(1); j++)
  16.                 {
  17.                     array[i, j] = rand.Next(1, 100);
  18.                     Console.Write($"{array[i,j]} ");
  19.                 }
  20.                 Console.WriteLine();
  21.             }
  22.  
  23.             for (int i = 0; i < array.GetLength(0); i++)
  24.             {
  25.                 for (int j = 0; j < array.GetLength(1); j++)
  26.                 {
  27.                     if (maxElement < array[i, j])
  28.                     {
  29.                         maxElement = array[i, j];
  30.                     }
  31.                 }
  32.             }
  33.  
  34.             Console.WriteLine($"\nMax Element: {maxElement}\n");
  35.  
  36.             for (int i = 0; i < array.GetLength(0); i++)
  37.             {
  38.                 for (int j = 0; j < array.GetLength(1); j++)
  39.                 {
  40.                     if (maxElement == array[i, j])
  41.                     {
  42.                         array[i,j] = 0;
  43.                     }
  44.                 }
  45.             }
  46.  
  47.             for (int i = 0; i < array.GetLength(0); i++)
  48.             {
  49.                 for (int j = 0; j < array.GetLength(1); j++)
  50.                 {
  51.                     Console.Write($"{array[i, j]} ");
  52.                 }
  53.                 Console.WriteLine();
  54.             }
  55.         }
  56.     }
  57. }
Add Comment
Please, Sign In to add comment