Anonim_999

Untitled

Jan 10th, 2021 (edited)
1,075
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.10 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp9
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Random rand = new Random();
  10.             int[] array = new int[30];
  11.  
  12.             for (int i = 0; i < array.GetLength(0); i++)
  13.             {
  14.                 array[i] = rand.Next(0, 11);
  15.                 Console.Write($"{array[i]} ");
  16.             }
  17.  
  18.             Console.WriteLine($"\nЛокальные максимумы:");
  19.  
  20.             if (array[0] > array[1])
  21.             {
  22.                 Console.Write($"{array[0]} ");
  23.             }
  24.  
  25.             for (int i = 1; i < array.GetLength(0) - 1; i++)
  26.             {
  27.  
  28.                 if (array[i] > array[i - 1] && array[i] > array[i + 1])
  29.                 {
  30.                     Console.Write($"{array[i]} ");
  31.                 }
  32.             }
  33.  
  34.             if (array[array.GetLength(0) - 1] > array[array.GetLength(0) - 2])
  35.             {
  36.                 Console.Write($"{array[array.GetLength(0) - 1]} ");
  37.             }
  38.  
  39.             Console.ReadKey();
  40.             Console.WriteLine();
  41.            
  42.         }
  43.     }
  44. }
Add Comment
Please, Sign In to add comment