Skip to content

Instantly share code, notes, and snippets.

@Strelok78
Last active April 29, 2025 13:34
Show Gist options
  • Save Strelok78/cc43c45f5dfb0943e84417c8a1ba7edb to your computer and use it in GitHub Desktop.
Save Strelok78/cc43c45f5dfb0943e84417c8a1ba7edb to your computer and use it in GitHub Desktop.
Find local max values (value bigger than it's neighbours - edge values compare to it's only neighbour)
using System.Collections;
using System.Diagnostics;
using System.Text;
namespace iJuniorPractice;
class Program
{
static void Main(string[] args)
{
int[] numbers = new int[30];
Random random = new Random();
int maxRandomValue = 100;
int lastIndex;
Console.WriteLine("numbers:");
for (int i = 0; i < numbers.Length; i++)
{
numbers[i] = random.Next(maxRandomValue + 1);
Console.Write(numbers[i] + " ");
}
lastIndex = numbers.Length - 1;
Console.WriteLine("\nLocal max values: ");
if (numbers[0] > numbers[1])
{
Console.Write(numbers[0] + " ");
}
for (int i = 1; i < numbers.Length - 1; i++)
{
if (numbers[i] > numbers[i + 1] && numbers[i] > numbers[i - 1])
{
Console.Write(numbers[i] + " ");
}
}
if (numbers[lastIndex] > numbers[lastIndex - 1])
{
Console.WriteLine(numbers[lastIndex]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment