Advertisement
Guest User

Ivan

a guest
Jan 25th, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ArrayLocalMax
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int[] array = { 9, 5, 4, 3, 4, 5, 3, 4, 5, 4, 5, 4, 3, 7, 8, 9, 7, 6, 7, 6, 4, 6, 4, 5, 3, 5, 3, 5, 3, 9 };
  14.  
  15.             for (int i = 0; i < array.Length; i++)
  16.             {
  17.                 if (i != 0 && (array.Length -1) != i)
  18.                 {
  19.                     if (array[i] > array[i - 1] && array[i] > array[i + 1])
  20.                     {
  21.                         Console.Write(array[i] + " ");
  22.                     }
  23.                 }
  24.                 else if(i == 0)
  25.                 {
  26.                     if (array[i] > array[i + 1])
  27.                     {
  28.                         Console.Write(array[i] + " ");
  29.                     }
  30.                 }
  31.                 else
  32.                 {
  33.                     if (array[i] > array[i - 1])
  34.                     {
  35.                         Console.Write(array[i] + " ");
  36.                     }
  37.                 }
  38.             }
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement