AlexRaynor

3.4 MatrixMaxElement

Sep 5th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApplication2
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             const int size = 10;
  10.             int[,] matrix = new int[size, size];
  11.             matrix[2, 7] = 10;
  12.             matrix[3, 1] = 99;
  13.             matrix[5, 5] = 154;
  14.             Console.WriteLine("Исходная матрица");
  15.             int max = matrix[0, 0], k = 0, m = 0;
  16.             foreach (int x in matrix)
  17.             {
  18.                 Console.Write(x + " ");
  19.             }
  20.             for (int i = 0; i < size; i++)
  21.                 for (int j = 0; j < size; j++)
  22.                     if (matrix[i, j] > max)
  23.                     {
  24.                         max = matrix[i, j];
  25.                         k = i;
  26.                         m = j;
  27.                     }
  28.             Console.WriteLine();
  29.             Console.WriteLine("Максимальный элемент = " + max);
  30.             matrix[k, m] = 0;
  31.             Console.WriteLine("Новая матрица, с заменой на 0 ");
  32.  
  33.             foreach (int x in matrix)
  34.             {
  35.                 Console.Write(x + " ");
  36.  
  37.  
  38.             }
  39.  
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment