MaoChessy

Task 17

Oct 27th, 2020 (edited)
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2.  
  3. namespace C_sharp_Light
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int[] array = new int[30];
  10.             Random rand = new Random();
  11.  
  12.             for (int i = 0; i < array.Length; i++)
  13.             {
  14.                 array[i] = rand.Next(0, 101);
  15.                 Console.Write($"({i+1}){array[i]} ");
  16.             }
  17.             Console.WriteLine("\n");
  18.  
  19.             for (int i = 0; i < array.Length; i++)
  20.             {
  21.                 if (i != 0 && i != array.Length - 1)
  22.                 {
  23.                     if (array[i] > array[i + 1] && array[i] > array[i - 1])
  24.                         Console.WriteLine($"({i+1}){array[i]}-локальный максимум");
  25.                 }
  26.                 else if (i == 0)
  27.                 {
  28.                     if (array[i] > array[i + 1])
  29.                         Console.WriteLine($"({i+1}){array[i]}-локальный максимум");
  30.                 }
  31.                 else if (i != array.Length)
  32.                 {
  33.                     if (array[i] > array[i - 1])
  34.                         Console.WriteLine($"({i+1}){array[i]}-локальный максимум");
  35.                 }
  36.             }
  37.  
  38.             Console.ReadKey();
  39.         }
  40.     }
  41. }
Add Comment
Please, Sign In to add comment