aleahim

FirstBiggestThanHisNeighbours

Jan 30th, 2013
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.63 KB | None | 0 0
  1. using System;
  2.  
  3. class FirstBiggestThanHisNeighbours
  4. {
  5.     static void Main()
  6.     {
  7.         int[] arr = { 1, 2, 2, 2, 1, 1, 4 };
  8.         for (int i = 1; i < arr.Length - 1; i++)
  9.         {
  10.             if (CompareNumberAtGivenPosition(arr, i) == 1)
  11.             {
  12.                 Console.WriteLine(i);
  13.                 break;
  14.             }
  15.             if (i == arr.Length - 2) Console.WriteLine("-1");  
  16.         }  
  17.     }
  18.  
  19.     static int CompareNumberAtGivenPosition(int[] arr, int index)
  20.     {
  21.         if ((arr[index - 1] < arr[index]) && (arr[index + 1] < arr[index]))
  22.             return 1;
  23.         else return -1;
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment