Advertisement
Dr_Max_Experience

Task 17

Aug 18th, 2021 (edited)
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.49 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 Homework_1
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.Write("Введите размер массива: ");
  14.             int arrayLength = Convert.ToInt32(Console.ReadLine());
  15.             int[] array = new int[arrayLength];
  16.             Random random = new Random();
  17.             Console.Write("Массив: ");
  18.  
  19.             for (int i = 0; i < arrayLength; i++)
  20.             {
  21.                 array[i] = random.Next(0, 10);
  22.                 Console.Write(array[i] + " ");
  23.             }
  24.             Console.Write("\nЛокальные максимумы: ");
  25.  
  26.             for (int i = 0; i < arrayLength; i++)
  27.             {
  28.                 if (i == 0)
  29.                 {
  30.                     if (array[i] > array[(i + 1)])
  31.                     {
  32.                         Console.Write(array[i] + " ");
  33.                     }
  34.                 }
  35.                 else if (i == (arrayLength - 1))
  36.                 {
  37.                     if (array[i] > array[(i - 1)])
  38.                     {
  39.                         Console.Write(array[i] + " ");
  40.                     }
  41.                 }
  42.                 else if (array[(i - 1)] < array[i] && array[i] > array[(i + 1)])
  43.                 {
  44.                     Console.Write(array[i] + " ");
  45.                 }
  46.             }
  47.             Console.ReadKey();
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement