Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Локальный_максимум
- {
- class Program
- {
- static void Main(string[] args)
- {
- int kol = 0;
- 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 } };
- for (int i = 0; i < array.GetLength(0); ++i)
- {
- for (int j = 0; j < array.GetLength(1); ++j)
- {
- if (i != 0 && i != array.GetLength(1) && j != 0 && j != array.GetLength(1))
- {
- 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])
- {
- kol++;
- Console.Write(array[i, j] + " ");
- }
- }
- }
- }
- if (kol > 0)
- {
- Console.WriteLine($"Количество локальных максимумов = {kol}");
- }
- else { Console.WriteLine("Локальных максимумов нет ("); }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement