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