Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp1
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int[] array = new int[30];
  10.             Random random = new Random();
  11.             int current = 0;
  12.             int next = 0;
  13.             int previous = 0;
  14.  
  15.             for (int i = 0; i < array.Length; i++)
  16.             {
  17.                 array[i] = random.Next(1, 100);
  18.                 Console.WriteLine(array[i]);
  19.             }
  20.  
  21.             int j = 0;
  22.             do
  23.             {
  24.                 current = array[j];
  25.                 next = array[j + 1];
  26.  
  27.                 if (current > previous && current > next)
  28.                     Console.WriteLine("Найден локальный максимум " + current);
  29.  
  30.                 j++;
  31.                 previous = array[j - 1];
  32.  
  33.             } while (j < 29);
  34.  
  35.             if (array[array.Length-1] > array[array.Length - 2])
  36.                 Console.WriteLine("Найден локальный максимум " + array[array.Length - 1]);
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement