Advertisement
Vlad_Savitskiy

Max element

Apr 8th, 2020
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.89 KB | None | 0 0
  1. using System;
  2.  
  3. namespace CSLightFirst
  4. {
  5.     class Program
  6.     {
  7.         static void Main()
  8.         {
  9.             Random rand = new Random();
  10.             int[,] data = new int[10, 10];
  11.             int maxNumber = -1;
  12.             int maxNumPositionX = -1;
  13.             int maxNumPositionY = -1;
  14.  
  15.             Console.ForegroundColor = ConsoleColor.Blue;
  16.             Console.WriteLine("Исходный массив:\n");
  17.             Console.ForegroundColor = ConsoleColor.White;
  18.             for (int i = 0; i < data.GetLength(0); i++)
  19.             {
  20.                 for (int j = 0; j < data.GetLength(1); j++)
  21.                 {
  22.                     data[i, j] = rand.Next(1, 100);
  23.                     Console.Write(data[i, j] + " ");
  24.                     if (data[i, j] > maxNumber)
  25.                     {
  26.                         maxNumber = data[i, j];
  27.                         maxNumPositionY = i;
  28.                         maxNumPositionX = j;
  29.                     }
  30.                 }
  31.                 Console.WriteLine();
  32.             }
  33.  
  34.             data[maxNumPositionY, maxNumPositionX] = 0;
  35.  
  36.             Console.ForegroundColor = ConsoleColor.Blue;
  37.             Console.WriteLine("\nПолученный массив:\n");
  38.             Console.ForegroundColor = ConsoleColor.White;
  39.             for (int i = 0; i < data.GetLength(0); i++)
  40.             {
  41.                 for (int j = 0; j < data.GetLength(1); j++)
  42.                 {
  43.                     Console.Write(data[i, j] + " ");
  44.                 }
  45.                 Console.WriteLine();
  46.             }
  47.  
  48.             Console.ForegroundColor = ConsoleColor.Blue;
  49.             Console.WriteLine("\nНаибольший элемент " +
  50.                               $"находится в позиции {maxNumPositionY} | {maxNumPositionX} и равен {maxNumber}");
  51.             Console.ForegroundColor = ConsoleColor.White;
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement