Advertisement
RedFlys

HomeWork17. Local max

Aug 26th, 2020
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.80 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp17.LocalMax
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int[] array = new int[30];
  10.             Random rand = new Random();
  11.  
  12.             for (int i = 0; i < array.Length; i++)
  13.             {
  14.                 array[i] = rand.Next(0, 100);
  15.             }
  16.  
  17.             if (array[0] > array[1])
  18.                 Console.Write(array[0] + " ");
  19.  
  20.             for (int i = 1; i < array.Length - 1; i++)
  21.             {
  22.                 if (array[i] > array[i - 1] && array[i] > array[i + 1])
  23.                     Console.Write(array[i] + " ");
  24.             }
  25.  
  26.             if (array[array.Length - 1] > array[array.Length - 2])
  27.                 Console.Write(array[array.Length - 1]);
  28.  
  29.             Console.ReadKey();
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement