Advertisement
VodVas

Локальные максимумы

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