Advertisement
Comrade_Sharikov

local max

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