Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Homework_1
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.Write("Введите размер массива: ");
- int arrayLength = Convert.ToInt32(Console.ReadLine());
- int[] array = new int[arrayLength];
- Random random = new Random();
- Console.Write("Массив: ");
- for (int i = 0; i < arrayLength; i++)
- {
- array[i] = random.Next(0, 10);
- Console.Write(array[i] + " ");
- }
- Console.Write("\nЛокальные максимумы: ");
- for (int i = 0; i < arrayLength; i++)
- {
- if (i == 0)
- {
- if (array[i] > array[(i + 1)])
- {
- Console.Write(array[i] + " ");
- }
- }
- else if (i == (arrayLength - 1))
- {
- if (array[i] > array[(i - 1)])
- {
- Console.Write(array[i] + " ");
- }
- }
- else if (array[(i - 1)] < array[i] && array[i] > array[(i + 1)])
- {
- Console.Write(array[i] + " ");
- }
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement