Skip to content

Instantly share code, notes, and snippets.

@FleamRus
Last active April 29, 2024 04:40
Show Gist options
  • Save FleamRus/1fbf76f24f064c98acfd3ff7d10fb150 to your computer and use it in GitHub Desktop.
Save FleamRus/1fbf76f24f064c98acfd3ff7d10fb150 to your computer and use it in GitHub Desktop.
Локальные максимумы
using System;
namespace Локальные_максимумы
{
internal class Program
{
static void Main(string[] args)
{
Random random = new Random();
int minRandom = 1;
int maxRandom = 11;
int elementsArray = 30;
int startIndex = 1;
int correctionIndex = 1;
int[] numbers = new int[elementsArray];
int endIndex = numbers.Length - 1;
Console.WriteLine("\tМассив:\n");
for (int i = 0; i < numbers.Length; i++)
{
numbers[i] = random.Next(minRandom, maxRandom);
Console.Write(numbers[i] + " ");
}
Console.WriteLine();
Console.WriteLine("\tЛокальные максимумы:\t");
if (numbers[0] > numbers[1])
{
Console.Write(numbers[0] + " ");
}
for (int i = startIndex; i < elementsArray - correctionIndex; i++)
{
if (numbers[i] > numbers[i - correctionIndex] & numbers[i] > numbers[i + correctionIndex])
{
Console.Write(numbers[i] + " ");
}
}
if (numbers[endIndex] > numbers[endIndex - correctionIndex])
{
Console.WriteLine(numbers[endIndex] + " ");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment