illiden

MaxElement

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