12Vitaly

15

Aug 31st, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.08 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 egor
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Random rand = new Random();
  14.             int[] array = new int[30];
  15.  
  16.             for (int i = 0; i < array.Length; i++)
  17.             {
  18.                 array[i] = rand.Next(0, 31);
  19.                 Console.Write(array[i] + " ");
  20.             }
  21.  
  22.             Console.WriteLine("\nЛокальные максимумы массива: ");
  23.  
  24.             if (array[0] > array[1])
  25.             {
  26.                 Console.Write(array[0] + " ");
  27.             }
  28.  
  29.             for (int i = 1; i < array.Length - 1; i++)
  30.                {
  31.                   if (array[i] > array[i + 1])
  32.                   {
  33.                     Console.Write(array[i] + " ");
  34.                   }
  35.                }
  36.  
  37.             if (array[array.Length - 1] > array[array.Length - 2])
  38.             {
  39.                 Console.Write(array[array.Length - 1]);
  40.             }
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment