Advertisement
Guest User

3.4

a guest
May 20th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.46 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 Les3
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.  
  14.             Console.Title = "3.4 Наибольшый элемент";
  15.  
  16.             int[,] arrMatrix = {
  17.                                  { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 },
  18.                                  { 2, 0, 6, 5, 8, 9, 3, 2, 3, 2 },
  19.                                  { 3, 5, 11, 9, 78, 74, 3, 1, 2, 2 },
  20.                                  { 4, 9, 6, 1, 2, 2, 3, 2, 9, 2 },
  21.                                  { 5, 5, 60, 0, 2, 5, 3, 2, 7, 2 },
  22.                                  { 6, 5, 6, 3, 8, 9, 3, 2, 0, 2 },
  23.                                  { 7, 7, 79, 5, 9, 24, 3, 1, 9, 2 },
  24.                                  { 8, 5, 6, 8, 2, 0, 3, 2, 4, 2 },
  25.                                  { 9, 22, 6, 15, 2, 5, 13, 0, 2, 2 },
  26.                                  { 0, 5, 6, 5, 2, 4, 3, 2, 9, 2 }
  27.                                };
  28.  
  29.             int iMax = 0;
  30.             int x = 0;
  31.             int y = 0;
  32.  
  33.             for (int i = 0; i < arrMatrix.GetLength(0); i++)
  34.             {
  35.                 for (int j = 0; j < arrMatrix.GetLength(1); j++)
  36.                 {
  37.                     if(arrMatrix[i, j] > iMax)
  38.                     {
  39.                         iMax = arrMatrix[i, j];
  40.                         x = i;
  41.                         y = j;
  42.                     }
  43.                 }
  44.                 Console.WriteLine();
  45.             }
  46.  
  47.             Console.SetCursorPosition(0, 0);
  48.             for (int i = 0; i < arrMatrix.GetLength(0); i++)
  49.             {
  50.                 for (int j = 0; j < arrMatrix.GetLength(1); j++)
  51.                 {
  52.                     Console.Write(arrMatrix[i, j] + " ");
  53.                 }
  54.                 Console.WriteLine();
  55.             }
  56.  
  57.             Console.WriteLine();
  58.             Console.WriteLine($"Наибольшее значение элементов матрицы: {iMax}");
  59.             arrMatrix[x, y] = 0;
  60.  
  61.             Console.SetCursorPosition(0, arrMatrix.GetLength(0) + 4);
  62.             for (int i = 0; i < arrMatrix.GetLength(0); i++)
  63.             {
  64.                 for (int j = 0; j < arrMatrix.GetLength(1); j++)
  65.                 {
  66.                     Console.Write(arrMatrix[i, j] + " ");
  67.                 }
  68.                 Console.WriteLine();
  69.             }
  70.  
  71.             Console.ReadKey();
  72.  
  73.         }
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement