Montagne94

20. Наибольший элемент

Jan 9th, 2025
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.69 KB | Source Code | 0 0
  1. using System;
  2.  
  3. namespace HomeWork
  4. {
  5.     internal class Program
  6.     {
  7.         public static void Main(string[] args)
  8.         {
  9.             Random random = new Random();
  10.  
  11.             int min = 1;
  12.             int max = 9;
  13.             int targetNumber = 0;
  14.  
  15.             int rows = 10;
  16.             int columns = 10;
  17.             int[,] matrix = new int[rows, columns];
  18.  
  19.             Console.WriteLine("Исходная матрица:\n");
  20.  
  21.             for (int i = 0; i < matrix.GetLength(0); i++)
  22.             {
  23.                 for (int j = 0; j < matrix.GetLength(1); j++)
  24.                 {
  25.                     matrix[i, j] = random.Next(min, max + 1);
  26.                     Console.Write(matrix[i, j] + " ");
  27.                 }
  28.  
  29.                 Console.WriteLine();
  30.             }
  31.  
  32.             int maxValue = matrix[0, 0];
  33.  
  34.             for (int i = 0; i < matrix.GetLength(0); i++)
  35.             {
  36.                 for (int j = 0; j < matrix.GetLength(1); j++)
  37.                 {
  38.                     if (maxValue < matrix[i, j])
  39.                         maxValue = matrix[i, j];
  40.                 }
  41.             }
  42.  
  43.             Console.WriteLine("Наибольший элемент матрицы: " + maxValue + "\n");
  44.             Console.WriteLine("Итоговая матрица:\n");
  45.  
  46.             for (int i = 0; i < matrix.GetLength(0); i++)
  47.             {
  48.                 for (int j = 0; j < matrix.GetLength(1); j++)
  49.                 {
  50.                     if (maxValue == matrix[i, j])
  51.                         matrix[i, j] = targetNumber;
  52.  
  53.                     Console.Write(matrix[i, j] + " ");
  54.                 }
  55.  
  56.                 Console.WriteLine();
  57.             }
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment