Advertisement
VoVfe

Untitled

Apr 8th, 2020
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.38 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[] array = new int[30];
  14.             Random rand = new Random();
  15.             int maxValue = int.MinValue;
  16.  
  17.             for (int j = 0; j < array.Length; j++)
  18.             {
  19.                 array[j] = rand.Next(0, 9);
  20.                 Console.Write(array[j] + " ");
  21.             }
  22.             for (int i = 1; i < array.Length - 1; i++)
  23.             {
  24.                     if (array[i - 1] < array[i] && array[i] > array[i + 1])
  25.                     {
  26.                         if (maxValue < array[i])
  27.                         {
  28.                             maxValue = array[i];
  29.                             Console.Write($"\nмаксимальный элемент <{maxValue}>");
  30.                         }
  31.                     }
  32.             }
  33.             if (array[0] > array[1])
  34.             {
  35.                 Console.Write($"\nкрайний элемент <{array[0]}>");
  36.             }
  37.             if (array[array.Length - 1] > array[array.Length - 2])
  38.             {
  39.                 Console.WriteLine($"\nкрайний элемент <{array[array.Length - 1]}>");
  40.             }
  41.             Console.ReadKey();
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement