Advertisement
callumbinner22

pg347 Task 5

Dec 6th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.58 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication49
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int position = 5;
  14.             int[] myarray = { 1, 5, 8, 7, 8, 9, 1 };
  15.             Console.WriteLine(check(myarray,position));
  16.         }
  17.                 static string check(int[] myarray, int position)
  18.         {
  19.                  
  20.                         if (position == myarray.Length)
  21.                         {
  22.                             return "Not valid not neighbors";
  23.                         }
  24.                         if (myarray[position] < myarray[position+1] && myarray[position] > myarray[position-1])
  25.                         {
  26.                             return "The biggest number is " + (myarray[position + 1]);
  27.                         }
  28.                         if (myarray[position] > myarray[position + 1] && myarray[position] < myarray[position - 1])
  29.                         {
  30.                             return "The biggest number is " + (myarray[position-1]);
  31.                         }
  32.                          if (myarray[position] > myarray[position + 1] && myarray[position] > myarray[position - 1])
  33.                         {
  34.                             return "The biggest number is " + (myarray[position]);
  35.                         }
  36.                          else
  37.                          {
  38.                              return Convert.ToString(0);
  39.                          }
  40.                    
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement