Advertisement
LeRoY_Go

Untitled

Jan 29th, 2022
1,121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.43 KB | None | 0 0
  1. using System;
  2.  
  3. namespace C_Sharp_Junior
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Console.Write("Введите размер массива: ");
  10.             int userInput = Convert.ToInt32(Console.ReadLine());
  11.             int[] array = new int[userInput];
  12.             Random random = new Random();
  13.             for (int i = 0; i < array.Length; i++)
  14.             {
  15.                 array[i] = random.Next(99);
  16.                 Console.Write(array[i] + " ");
  17.             }
  18.             Console.WriteLine();
  19.             Console.Write("Локальный максимум:");
  20.             for (int i = 0; i < array.Length; i++)
  21.             {
  22.                 if (i == 0)
  23.                 {
  24.                     if (array[i] > array[i + 1])
  25.                     {
  26.                         Console.Write(" " + array[i]);
  27.                     }
  28.                 }
  29.                 else if (i <= array.Length)
  30.                 {
  31.                     if (array[i] > array[i - 1])
  32.                     {
  33.                         Console.Write(" " + array[i]);
  34.                     }
  35.                 }
  36.                 else
  37.                 {
  38.                     if (array[i] > array[i - 1] && array[i] > array[i + 1])
  39.                     {
  40.                         Console.Write(" " + array[i]);
  41.                     }
  42.                 }
  43.             }
  44.             Console.ReadLine();
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement