Last active
May 2, 2024 05:40
-
-
Save FleamRus/a6a3506621b0548316886bd38ea4fc9e to your computer and use it in GitHub Desktop.
Подмассив повторений чисел
This file contains 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; | |
namespace Подмассив_повторений_чисел | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Random random = new Random(); | |
int minRandom = 1; | |
int maxRandom = 10; | |
int elementsArray = 30; | |
int maxCountRepeat = 0; | |
int repeatedNumber = 0; | |
int countRepeat = 0; | |
int[] numbers = new int[elementsArray]; | |
Console.WriteLine("Ваш массив: \n"); | |
for (int i = 0; i < numbers.Length; i++) | |
{ | |
numbers[i] = random.Next(minRandom, maxRandom); | |
Console.Write(numbers[i] + " "); | |
} | |
Console.WriteLine(); | |
for (int i = 0; i < numbers.Length - 1; i++) | |
{ | |
if (numbers[i + 1] == numbers[i]) | |
{ | |
countRepeat++; | |
if (countRepeat > maxCountRepeat) | |
{ | |
maxCountRepeat = countRepeat; | |
repeatedNumber = numbers[i]; | |
} | |
} | |
else | |
{ | |
countRepeat = 1; | |
} | |
} | |
Console.WriteLine("Большее количество раз повторяется: " + repeatedNumber); | |
Console.WriteLine("Количество повторений: " + maxCountRepeat); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment