Advertisement
nikitaTheSlayer

Lesson: array3

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