Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class FirstBiggestThanHisNeighbours
- {
- static void Main()
- {
- int[] arr = { 1, 2, 2, 2, 1, 1, 4 };
- for (int i = 1; i < arr.Length - 1; i++)
- {
- if (CompareNumberAtGivenPosition(arr, i) == 1)
- {
- Console.WriteLine(i);
- break;
- }
- if (i == arr.Length - 2) Console.WriteLine("-1");
- }
- }
- static int CompareNumberAtGivenPosition(int[] arr, int index)
- {
- if ((arr[index - 1] < arr[index]) && (arr[index + 1] < arr[index]))
- return 1;
- else return -1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment