Advertisement
bonumopus

arraytask3

Apr 14th, 2020
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.37 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 arraytask3
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Random rand = new Random();
  14.             int[,] aMatrix = new int[10, 10];
  15.             int maxNumber = int.MinValue;
  16.  
  17.             // Заполнение ячеек матрицы числами
  18.             for (int i = 0; i < aMatrix.GetLength(0); i++)
  19.             {
  20.                 for (int j = 0; j < aMatrix.GetLength(1); j++)
  21.                 {
  22.                     aMatrix[i,j] = rand.Next(100, 1000);
  23.                 }
  24.             }
  25.             // Вывод исходной матрицы
  26.             Console.WriteLine("Дана матрица А:\n");
  27.             for (int i = 0; i < aMatrix.GetLength(0); i++)
  28.             {
  29.                 for (int j = 0; j < aMatrix.GetLength(1); j++)
  30.                 {
  31.                     Console.Write(aMatrix[i,j] + " ");
  32.                 }
  33.                 Console.WriteLine();
  34.             }
  35.             // Поиск максимального числа
  36.             for (int i = 0; i < aMatrix.GetLength(0); i++)
  37.             {
  38.                 for (int j = 0; j < aMatrix.GetLength(1); j++)
  39.                 {
  40.                     if (maxNumber < aMatrix[i,j])
  41.                     {
  42.                         maxNumber = aMatrix[i, j];
  43.                     }
  44.                 }
  45.             }
  46.             Console.WriteLine("\nНаибольший элемент матрицы: " + maxNumber);
  47.             // Замена числа на 0 и отрисовка новой матрицы.
  48.             Console.WriteLine("\n\nПолученная матрица с заменой максимального числа на 0:\n");
  49.             for (int i = 0; i < aMatrix.GetLength(0); i++)
  50.             {
  51.                 for (int j = 0; j < aMatrix.GetLength(1); j++)
  52.                 {
  53.                     if (aMatrix[i, j] == maxNumber)
  54.                     {
  55.                         aMatrix[i, j] = 0;
  56.                         Console.ForegroundColor = ConsoleColor.Red;
  57.                     }
  58.                     Console.Write(aMatrix[i, j] + " ");
  59.                     Console.ForegroundColor = ConsoleColor.White;
  60.                 }
  61.                 Console.WriteLine();
  62.             }
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement