Last active
April 29, 2025 13:34
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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