Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Локальные_максимумы
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- Console.Write("Введите размер массива: ");
- int arrayLenght = Convert.ToInt32(Console.ReadLine());
- int[] array = new int[arrayLenght];
- Random random = new Random();
- for (int i = 0; i < array.Length; i++)
- {
- array[i] = random.Next(0, 100);
- Console.Write(array[i] + " ");
- }
- Console.WriteLine();
- if (array[0] > array[1])
- {
- Console.Write($"Локальный максимум: {array[0]}" + " " + "\n");
- }
- for (int i = 1; i < array.Length - 1; i++)
- {
- if (array[i] > array[i + 1] && array[i] > array[i - 1])
- {
- Console.Write($"Локальный максимум: {array[i]}" + " " + "\n");
- }
- }
- if (array[array.Length - 1] > array[array.Length - 2])
- {
- Console.Write($"Локальный максимум: {array[array.Length-1]}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement