Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace LocalMaximums
- {
- class Program
- {
- private const string
- InitialArray = "Массив: ",
- LocalMaximumsText = "Локальные максимумы выделены красным: ",
- Separator = " ";
- private const int
- Min = 0, Max = 20, ArrayLength = 30;
- static void Main(string[] args)
- {
- int[] numbers = new int[ArrayLength];
- int[] maximums = new int[ArrayLength];
- Random random = new Random();
- for (int i = 0; i < ArrayLength; i++)
- {
- numbers[i] = random.Next(Min, Max);
- }
- for (int i = 0; i < ArrayLength; i++)
- {
- switch (i)
- {
- case 0:
- {
- maximums[i] = numbers[i + 1] < numbers[i] ? 1 : 0;
- break;
- }
- case ArrayLength - 1:
- {
- maximums[i] = numbers[i - 1] < numbers[i] ? 1 : 0;
- break;
- }
- default:
- {
- maximums[i] = numbers[i - 1] < numbers[i] && numbers[i + 1] < numbers[i] ? 1 : 0;
- break;
- }
- }
- }
- Console.WriteLine(InitialArray);
- Console.WriteLine(string.Join(Separator, numbers));
- Console.WriteLine(LocalMaximumsText);
- for (int i = 0; i < ArrayLength; i++)
- {
- Console.ForegroundColor = maximums[i] == 0 ? ConsoleColor.Gray : ConsoleColor.Red;
- Console.Write(numbers[i] + Separator);
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment