Advertisement
Vadim_Rogulev

Untitled

Apr 17th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 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, 5, 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.                
  20.                     if (i != 0 && i != array.GetLength(0)-1)
  21.                     {
  22.                         if (array[i] > array[i - 1] && array[i] > array[i + 1])
  23.                         {
  24.                             kol++;
  25.                             Console.Write(array[i] + " ");
  26.                         }
  27.                     }
  28.                
  29.             }
  30.             if (kol > 0)
  31.             {
  32.                 Console.WriteLine($"\nКоличество локальных максимумов = {kol}");
  33.             }
  34.             else { Console.WriteLine("Локальных максимумов нет ("); }
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement