Advertisement
RedFlys

Home Work 3.4

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