Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication6
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] myarray = { 1, 5, 8, 7, 8, 9, 1, 1, 7 };
- Check(myarray);
- }
- static void Check(int[] myarray)
- {
- int firstIndex = 0;
- for (int index = 1; index < myarray.Length - 1; index++)
- {
- int first = myarray[index];
- if ((first > myarray[index + 1]) && (first > myarray[index - 1]))
- {
- firstIndex = index;
- break;
- }
- else
- {
- firstIndex = -1;
- }
- }
- Console.WriteLine("The location of the first integer that is greater than both its neighbours to the left and right respectively is ... " + firstIndex + "(The array starts at zero)");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement