Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace HomeWork
- {
- class Program
- {
- static void Main(string[] args)
- {
- int numberItemsInArray = 10;
- int[] userArray = new int[numberItemsInArray];
- Random random = new Random();
- int minNumbermInArray = 1;
- int maxNumbermInArray = 70;
- for (int k = 0; k < numberItemsInArray; k++)
- {
- userArray[k] = random.Next(minNumbermInArray, maxNumbermInArray);
- }
- Console.WriteLine($"Исходный массив размером {numberItemsInArray} содержит:");
- for (int i = 0; i < userArray.Length; i++)
- {
- Console.Write($"{userArray[i]} ");
- }
- Console.WriteLine("\n----------------------------------");
- for (int j = 0; j < userArray.Length; j++)
- {
- bool isLocalMax = true;
- if (j == 0)
- {
- if (userArray[j] <= userArray[j + 1])
- {
- isLocalMax = false;
- }
- }
- else if (j == userArray.Length - 1)
- {
- if (userArray[j] <= userArray[j - 1])
- {
- isLocalMax = false;
- }
- }
- else
- {
- if (userArray[j] <= userArray[j - 1] || userArray[j] <= userArray[j + 1])
- {
- isLocalMax = false;
- }
- }
- if (isLocalMax == true)
- {
- Console.WriteLine($"Локальный максимум: {userArray[j]}, позиция: {j}");
- }
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment