Advertisement
bonumopus

arraytask3_2

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