Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class ElementCheck
- {
- static void Main()
- {
- Console.Write("How long to be the array:");
- int n = int.Parse(Console.ReadLine());
- int[] array = new int[n];
- InputArray(n, array);
- Console.Write("Which index you want to check - from 0 to N: ");
- int index = int.Parse(Console.ReadLine());
- CheckByIndex(n, array, index);
- }
- private static void InputArray(int n, int[] array)
- {
- Console.WriteLine("Enter the elements of the array:");
- for (int i = 0; i < n; i++)
- {
- array[i] = int.Parse(Console.ReadLine());
- }
- }
- private static void CheckByIndex(int n, int[] array, int index)
- {
- if (index == 0 || index == n)
- {
- Console.WriteLine("Number {0} on index {1} has only one neighbor!", array[index], index);
- }
- else if (array[index] > array[index - 1] && array[index] > array[index + 1])
- {
- Console.WriteLine("Number {0} on index {1} is bigger than its two neighbors", array[index], index);
- }
- else if (array[index] < array[index - 1] || array[index] < array[index + 1])
- {
- Console.WriteLine("Number {0} on index {1} is smaller than at least one of its two neighbors", array[index], index);
- }
- else
- {
- Console.WriteLine("Number {0} on index {1} is equal to its two neighbors", array[index], index);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment