Advertisement
Dr_Max_Experience

Task 16

Aug 18th, 2021 (edited)
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.81 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Homework_1
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int arrayXSize = 10;
  14.             int arrayYSize = 10;
  15.             int[,] array = new int[arrayXSize, arrayYSize];
  16.             int maxArrayItem = int.MinValue;
  17.             int countMaxArrayItem = 0;
  18.             int changeMaxArrayItem = 0;
  19.             Random random = new Random();
  20.             Console.WriteLine("Матрица");
  21.  
  22.             for (int i = 0; i < array.GetLength(0); i++)
  23.             {
  24.                 for (int j = 0; j < array.GetLength(1); j++)
  25.                 {
  26.                     array[i, j] = random.Next(10, 100);
  27.                     Console.Write(array[i, j] + " ");
  28.  
  29.                     if (maxArrayItem <= array[i, j])
  30.                     {
  31.                         maxArrayItem = array[i, j];
  32.                     }
  33.                 }
  34.                 Console.WriteLine();
  35.             }
  36.             Console.WriteLine("\nОбработаная матрица");
  37.  
  38.             for (int i = 0; i < array.GetLength(0); i++)
  39.             {
  40.                 for (int j = 0; j < array.GetLength(1); j++)
  41.                 {
  42.                     if (maxArrayItem == array[i, j])
  43.                     {
  44.                         countMaxArrayItem++;
  45.                         array[i, j] = changeMaxArrayItem;
  46.                     }
  47.                     Console.Write(array[i, j] + " ");
  48.                 }
  49.                 Console.WriteLine();
  50.             }
  51.             Console.WriteLine($"\nНаибольший элемент в матрице = {maxArrayItem} и он встречается {countMaxArrayItem} раз(а).");
  52.             Console.ReadKey();
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement