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 ConsoleApplication49
- {
- class Program
- {
- static void Main(string[] args)
- {
- int position = 5;
- int[] myarray = { 1, 5, 8, 7, 8, 9, 1 };
- Console.WriteLine(check(myarray,position));
- }
- static string check(int[] myarray, int position)
- {
- if (position == myarray.Length)
- {
- return "Not valid not neighbors";
- }
- if (myarray[position] < myarray[position+1] && myarray[position] > myarray[position-1])
- {
- return "The biggest number is " + (myarray[position + 1]);
- }
- if (myarray[position] > myarray[position + 1] && myarray[position] < myarray[position - 1])
- {
- return "The biggest number is " + (myarray[position-1]);
- }
- if (myarray[position] > myarray[position + 1] && myarray[position] > myarray[position - 1])
- {
- return "The biggest number is " + (myarray[position]);
- }
- else
- {
- return Convert.ToString(0);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement