dxoraxs

Untitled

Apr 13th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.33 KB | None | 0 0
  1. using System;
  2.  
  3. namespace homework
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Random rand = new Random();
  10.             int[,] A = new int[30,30];
  11.  
  12.             for (int i=0; i< A.GetLength(0);i++)
  13.             {
  14.                 for (int j=0; j< A.GetLength(1);j++)
  15.                 {
  16.                     A[i,j]=rand.Next(10, 100);
  17.                 }
  18.             }
  19.             string number = "";
  20.             for (int i=0; i< A.GetLength(0);i++)
  21.             {
  22.                 for (int j=0; j< A.GetLength(1);j++)
  23.                 {
  24.                     if ( (i>0 && i < A.GetLength(0) -1) && (j>0 && j < A.GetLength(1) -1))
  25.                     {
  26.                         if (
  27.                         A[i, j] > A[i - 1, j -1] &&
  28.                         A[i, j] > A[i - 1, j] &&
  29.                         A[i, j] > A[i - 1, j +1] &&
  30.                         A[i, j] > A[i , j - 1] &&
  31.                         A[i, j] > A[i, j + 1] &&
  32.                         A[i, j] > A[i + 1, j- 1] &&
  33.                         A[i, j] > A[i + 1, j] &&
  34.                         A[i, j] > A[i + 1, j +1]
  35.                         ) number+= " | " + A[i, j];
  36.                     }
  37.                 }
  38.             }
  39.             Console.WriteLine("Все локальные максимумы:\n"+number);
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment