Advertisement
AlexRaynor

3.5 LocalMaximum3

Sep 11th, 2019
108
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 ConsoleApplication2
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int[] array = new int[30];
  10.             Random rand = new Random();
  11.             for (int i = 0; i < array.Length; i++)
  12.             {
  13.                 array[i] = rand.Next(0, 100);
  14.                 Console.Write(array[i] + " ");
  15.             }
  16.  
  17.  
  18.             if (array[0] > array[1])
  19.             {
  20.                 Console.WriteLine("\n Локальный максимум " + array[0]);
  21.             }
  22.  
  23.  
  24.             for (int i = 1; i < array.Length - 1; i++)
  25.             {
  26.                 if (array[i] > array[i - 1] && array[i] > array[i + 1])
  27.                 {
  28.                     Console.WriteLine("Локальный максимум " + array[i]);
  29.  
  30.                 }
  31.             }
  32.  
  33.             if (array[array.Length - 1] > array[array.Length - 2])
  34.             {
  35.                 Console.WriteLine("Локальный максимум " + array[array.Length - 1]);
  36.             }
  37.  
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement