Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace LocalMax
- {
- class Program
- {
- static void Main(string[] args)
- {
- const int elementsInArray = 30;
- int[] array = new int[elementsInArray];
- Random rand = new Random();
- Console.WriteLine("Исходный массив: ");
- if (array.Length == 1) Console.Write(array[0]);
- for (int i = 0; i < array.Length; i++)
- {
- array[i] = rand.Next(1, 100);
- Console.Write(array[i] + " ");
- }
- Console.Write("\nЛокальные максимумы: \n");
- for (int i = 0; i < array.Length; i++)
- {
- if (i == 0 && array[i] > array[i + 1])
- {
- Console.Write(array[i] + " ");
- }
- else if (i == array.Length - 1 && array[i] > array[i - 1])
- {
- Console.Write(array[i] + " ");
- }
- else if (array[i] > array[i - 1] && array[i] > array[i + 1])
- {
- Console.Write(array[i] + " ");
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment