Advertisement
Vadim_Rogulev

Untitled

Apr 17th, 2019
115
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. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Локальный_максимум
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int kol = 0;
  14.             int[,] array = { { 0, 2, 3, 4, 5 }, { 6, 7, 8, 9, 10 }, { 11, 12, 13, 14, 15 },{ 16, 17, 18, 19, 20}, { 21, 22, 23, 24, 25 }, {26,27,28,29,30 } };
  15.  
  16.  
  17.             for (int i = 0; i < array.GetLength(0); ++i)
  18.             {
  19.                 for (int j = 0; j < array.GetLength(1); ++j)
  20.                 {
  21.                     if (i != 0 && i != array.GetLength(1) && j != 0 && j != array.GetLength(1))
  22.                     {
  23.                         if (array[i, j] > array[i - 1, j] && array[i, j] > array[i + 1, j] && array[i, j] > array[i, j - 1] && array[i, j] > array[i, j + 1])
  24.                         {
  25.                             kol++;
  26.                             Console.Write(array[i, j] + " ");
  27.                         }
  28.                     }
  29.                 }
  30.             }
  31.             if (kol > 0)
  32.             {
  33.                 Console.WriteLine($"Количество локальных максимумов = {kol}");
  34.             }
  35.             else { Console.WriteLine("Локальных максимумов нет ("); }
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement