Advertisement
growhack

Task with MaxValue

Mar 31st, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.02 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[] tempArray = 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.                         tempArray[0] = i;
  31.                         tempArray[1] = j;
  32.                     }
  33.                 }
  34.             }
  35.             for (int i = 0; i < array.GetLength(0); i++)
  36.             {
  37.                 for (int j = 0; j < array.GetLength(1); j++)
  38.                 {
  39.                     if (tempArray[0] == i && tempArray[1] == j)
  40.                     {
  41.                         array[i, j] = 0;
  42.                     }
  43.                 }
  44.             }
  45.             Console.WriteLine("Измененная матрица:");
  46.             for (int i = 0; i < array.GetLength(0); i++)
  47.             {
  48.                 for (int j = 0; j < array.GetLength(1); j++)
  49.                 {
  50.                     Console.Write(array[i, j] + " ");
  51.                 }
  52.                 Console.WriteLine();
  53.             }
  54.             Console.Write("Максимально число - " + maxValue + " Находится по приведенным к нормальному виду координатам: " + (tempArray[0] + 1) + " | " + (tempArray[1] + 1));
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement