nKolchakoV

Untitled

Jan 4th, 2014
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 KB | None | 0 0
  1. using System;
  2.  
  3.     class Program
  4.     {
  5.         static void BiggerThanNeighbors(int[] array, int element)
  6.         {
  7.             if (element == 0 | element == array.Length - 1)
  8.             {
  9.                 Console.WriteLine("Incorrect Position (first or last position) !");
  10.                     return;
  11.             }
  12.             if (array[element] > array[element + 1] && array[element] > array[element - 1])
  13.             {
  14.                 Console.WriteLine("Yes! {0} < {1} > {2}", array[element - 1], array[element], array[element + 1]);
  15.             }
  16.             else
  17.             {
  18.                 Console.WriteLine("Nope.");
  19.             }
  20.         }
  21.  
  22.         static void Main()
  23.         {
  24.             int[] array = { 3, 2, 5, -4, 3, 0, 1, 9, 2 };
  25.             Console.Write("Chose a position: ");
  26.             int position = int.Parse(Console.ReadLine());
  27.  
  28.             BiggerThanNeighbors(array, position);
  29.         }
  30.     }
Advertisement
Add Comment
Please, Sign In to add comment