NikaBang

ДЗ: Наибольший элемент

Oct 19th, 2025
1,908
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.23 KB | Gaming | 0 0
  1. internal class Program
  2. {
  3.     static void Main(string[] args)
  4.     {
  5.         int[,] array = new int[10, 10];
  6.         int maxValue = 0;
  7.         int newValueForMax = 0;
  8.         int minRandom = 1;
  9.         int maxRandom = 10;
  10.         Random random = new Random();
  11.         Console.WriteLine("Исходный массив:");
  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] = random.Next(minRandom, maxRandom);
  18.                 Console.Write(array[i, j] + " ");
  19.                
  20.                 if(maxValue <  array[i, j])
  21.                 {
  22.                     maxValue = array[i, j];
  23.                 }
  24.             }
  25.             Console.WriteLine();
  26.         }
  27.  
  28.         Console.WriteLine("\nИзменненый массив:");
  29.  
  30.         for (int i = 0; i < array.GetLength(0); i++)
  31.         {
  32.             for (int j = 0; j < array.GetLength(1); j++)
  33.             {
  34.                 if (maxValue == array[i, j])
  35.                 {
  36.                     array[i, j] = newValueForMax;
  37.                 }
  38.  
  39.                 Console.Write(array[i, j] + " ");
  40.             }
  41.             Console.WriteLine();
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment