Sininerebane

Untitled

Jun 11th, 2024
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.09 KB | Software | 0 0
  1. namespace Themostmaxelement
  2. {
  3.     internal class Program
  4.     {
  5.         static void Main(string[] args)
  6.         {
  7.             Console.OutputEncoding = Encoding.UTF8;
  8.             Random random = new Random();
  9.             int size = 10;
  10.             int[,] array = new int[size, size];
  11.             int maxElement = int.MinValue;
  12.             int minValue = 0;
  13.             int maxValue = 10;
  14.             int replacementMaxNumber = 0;
  15.  
  16.             for (int i = 0; i < array.GetLength(0); i++)
  17.             {
  18.                 for (int j = 0; j < array.GetLength(1); j++)
  19.                 {
  20.                     array[i, j] = random.Next(minValue, maxValue);
  21.                 }
  22.             }
  23.  
  24.             Console.WriteLine("Исходная матрица\n");
  25.  
  26.             for (int i = 0; i < array.GetLength(0); i++)
  27.             {
  28.                 for (int j = 0; j < array.GetLength(1); j++)
  29.                 {
  30.                     Console.Write(array[i, j] + " ");
  31.                 }
  32.  
  33.                 Console.WriteLine();
  34.             }
  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 (array[i, j] >= maxElement)
  41.                     {
  42.                         maxElement = array[i, j];
  43.                     }
  44.                 }
  45.             }
  46.  
  47.             Console.WriteLine();
  48.             Console.WriteLine($"Наибольший элемент в матрица {maxElement}\n");
  49.             Console.WriteLine("Полученная матрица\n");
  50.  
  51.             for (int i = 0; i < array.GetLength(0); i++)
  52.             {
  53.                 for (int j = 0; j < array.GetLength(1); j++)
  54.                 {
  55.                    if (array[i, j] == maxElement)
  56.                     {
  57.                         array[i, j] = replacementMaxNumber;
  58.                     }  
  59.                    
  60.                     Console.Write(array[i, j] + " ");
  61.                 }
  62.  
  63.                 Console.WriteLine();      
  64.             }
  65.  
  66.             Console.ReadKey();
  67.         }
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment