Advertisement
RamGaal

HomaWork 3 ex.4

May 17th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.78 KB | None | 0 0
  1. using System;
  2.  
  3. class MainClass
  4. {
  5.     public static void Main(string[] args)
  6.     {
  7.         int[,] matrix = new int[10, 10];
  8.         int max = 0;
  9.  
  10.         Random rnd = new Random();
  11.  
  12.         Console.WriteLine("Исходная матрица\n");
  13.  
  14.         for (int x = 0; x < matrix.GetLength(0); x++)
  15.         {
  16.             for (int y = 0; y < matrix.GetLength(1); y++)
  17.             {
  18.                 matrix[x, y] = rnd.Next(1, 100);
  19.                 if (matrix[x, y] < 10)
  20.                 {
  21.                     Console.Write(" " + matrix[x, y] + " ");
  22.                 }
  23.                 else
  24.                 {
  25.                     Console.Write(matrix[x, y] + " ");
  26.                 }
  27.             }
  28.             Console.WriteLine();
  29.         }
  30.  
  31.         for (int x = 0; x < matrix.GetLength(0); x++)
  32.         {
  33.             for (int y = 0; y < matrix.GetLength(1); y++)
  34.             {
  35.                 if (max < matrix[x, y])
  36.                 {
  37.                     max = matrix[x, y];
  38.  
  39.                 }
  40.             }
  41.         }
  42.         Console.WriteLine("\nМаксимальный элемент = " + max);
  43.  
  44.         Console.WriteLine("Получена матрица\n");
  45.         for (int x = 0; x < matrix.GetLength(0); x++)
  46.         {
  47.             for (int y = 0; y < matrix.GetLength(1); y++)
  48.             {
  49.                 if (matrix[x, y] == max)
  50.                 {
  51.                     matrix[x, y] = 0;
  52.                 }
  53.                 if (matrix[x, y] < 10)
  54.                 {
  55.                     Console.Write(" " + matrix[x, y] + " ");
  56.                 }
  57.                 else
  58.                 {
  59.                     Console.Write(matrix[x, y] + " ");
  60.                 }
  61.             }
  62.             Console.WriteLine();
  63.         }
  64.  
  65.  
  66.         Console.ReadKey();
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement