Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save FleamRus/a6a3506621b0548316886bd38ea4fc9e to your computer and use it in GitHub Desktop.
Save FleamRus/a6a3506621b0548316886bd38ea4fc9e 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 = 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