Advertisement
growhack

Task with MaxValue

Apr 2nd, 2020
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.84 KB | None | 0 0
  1. using System;
  2.  
  3. namespace MaxElement
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int[,] array = new int[10, 10];
  10.             int maxValue = int.MinValue;
  11.             int[] coordinate = new int[2];
  12.             Random rand = new Random();
  13.             Console.WriteLine("Начальная матрица:");
  14.             for (int i = 0; i < array.GetLength(0); i++)
  15.             {
  16.                 for (int j = 0; j < array.GetLength(1); j++)
  17.                 {
  18.                     array[i, j] = rand.Next(0, 100);
  19.                     Console.Write(array[i, j] + " ");
  20.                 }
  21.                 Console.WriteLine();
  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 (maxValue < array[i, j])
  28.                     {
  29.                         maxValue = array[i, j];
  30.                         coordinate[0] = i;
  31.                         coordinate[1] = j;                        
  32.                     }
  33.                 }
  34.             }
  35.             Console.WriteLine("Измененная матрица:");
  36.             for (int i = 0; i < array.GetLength(0); i++)
  37.             {
  38.                 for (int j = 0; j < array.GetLength(1); j++)
  39.                 {
  40.                     if (coordinate[0] == i && coordinate[1] == j)
  41.                     {
  42.                         array[i, j] = 0;
  43.                     }
  44.                     Console.Write(array[i, j] + " ");
  45.                 }
  46.                 Console.WriteLine();
  47.             }
  48.             Console.Write("Максимально число - " + maxValue + ". координаты по которым находится измененное число " + coordinate[0] + " | " + coordinate[1]);
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement