Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace CSLightFirst
- {
- class Program
- {
- static void Main()
- {
- Random rand = new Random();
- int[] data = new int[30];
- for (int i = 0; i < data.Length; i++)
- data[i] = rand.Next(0, 9);
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.WriteLine($"Локальные максимумы массива из {data.Length} элем.:\n");
- Console.ForegroundColor = ConsoleColor.White;
- if (data.Length == 0)
- return;
- if (data.Length == 1)
- {
- Console.WriteLine(data[0]);
- return;
- }
- for (int i = 0; i < data.Length; i++)
- {
- if (i == 0)
- {
- if (data[i] > data[i + 1])
- Console.Write(data[i] + " ");
- continue;
- }
- if (i == data.Length - 1)
- {
- if (data[i] > data[i - 1])
- Console.Write(data[i] + " ");
- continue;
- }
- if (data[i] > data[i - 1] && data[i] > data[i + 1])
- Console.Write(data[i] + " ");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement