Advertisement
JohnJuly

Homework21

Nov 28th, 2023 (edited)
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.99 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 Homework21
  8. {
  9.     internal class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int numberToReplace = 0;
  14.             int maxElementMatrix = int.MinValue;
  15.             int[,] array = new int[10, 10]
  16.             {
  17.                 { 3,9,13,8,11,3,5,9,5,1},
  18.                 { 7,34,78,99,2,4,61,3,27,89},
  19.                 { 90,1,5,34,67,82,3,95,41,2},
  20.                 { 1,2,3,4,5,6,6,7,8,9},
  21.                 { 21,2,43,7,89,20,11,31,54,67 },
  22.                 { 9,5,7,22,34,5,66,78,9,2 },
  23.                 { 22,65,77,9,73,3,4,5,97,34 },
  24.                 { 44,3,9,87,6,55,25,3,1,77},
  25.                 { 3,22,11,32,45,69,89,4,7,41},
  26.                 { 11,3,44,76,54,43,4,99,12,32}
  27.             };
  28.  
  29.             Console.WriteLine("Исходная матрица:");
  30.  
  31.             for (int i = 0; i < array.GetLength(0); i++)
  32.             {
  33.                 for (int j = 0; j < array.GetLength(1); j++)
  34.                 {
  35.                     if (maxElementMatrix < array[i, j])
  36.                     {
  37.                         maxElementMatrix = array[i, j];
  38.                     }
  39.  
  40.                     Console.Write(array[i, j] + " ");
  41.                 }
  42.  
  43.                 Console.WriteLine();
  44.             }
  45.  
  46.             Console.WriteLine($"\nМаксимальный элемент в матрице: {maxElementMatrix}.");
  47.             Console.WriteLine("\nПолученная матрица:");
  48.  
  49.             for (int i = 0; i < array.GetLength(0); i++)
  50.             {
  51.                 for (int j = 0; j < array.GetLength(1); j++)
  52.                 {
  53.                     if (array[i, j] == maxElementMatrix)
  54.                     {
  55.                         array[i, j] = numberToReplace;
  56.                     }
  57.  
  58.                     Console.Write(array[i, j] + " ");
  59.                 }
  60.  
  61.                 Console.WriteLine();
  62.             }
  63.         }
  64.     }
  65. }
  66.  
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement