svetlozar_kirkov

Greater than Neighbours (Exercise)

Oct 3rd, 2014
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.06 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace ConsoleTesting2
  6. {
  7.     class ConsoleTesting2
  8.     {
  9.         static void Main()
  10.         {
  11.             int[] test = new int[10];
  12.             for (int i = 0; i < 10; i++)
  13.             {
  14.                 Console.Write("Index {0}: ", i);
  15.                 test[i] = int.Parse(Console.ReadLine());
  16.             }
  17.             Console.WriteLine();
  18.             char answer = 'n';
  19.             do
  20.             {
  21.                 Console.Write("Enter index to check: ");
  22.                 Console.WriteLine("Greater: {0}", GreaterThanNeighbours(int.Parse(Console.ReadLine()), test));
  23.                 Console.Write("Check another? (y/n): ");
  24.                 answer = char.Parse(Console.ReadLine());
  25.             } while (answer == 'y');
  26.            
  27.         }
  28.  
  29.         private static bool GreaterThanNeighbours(int index, params int[] array)
  30.         {
  31.             bool isGreater = array[index] > array[index + 1] && array[index] > array[index - 1];
  32.             return isGreater;
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment