Skip to content

Instantly share code, notes, and snippets.

@ssshh3
Created May 30, 2025 02:42
Show Gist options
  • Save ssshh3/c59e52dbe04f7f0ef2924c71513e7f3f to your computer and use it in GitHub Desktop.
Save ssshh3/c59e52dbe04f7f0ef2924c71513e7f3f to your computer and use it in GitHub Desktop.
namespace ConsoleApp1
{
internal class Program
{
static void Main(string[] args)
{
int[] array = new int[30];
int lastNumber = 10;
int repeatingNumber = 0;
int currentAmountOfRepetitions = 0;
int amountOfRepetitions = 0;
int currentNumber = array[0];
Random random = new Random();
for (int i = 0; i < array.Length; i++)
{
array[i] = random.Next(0, lastNumber);
Console.Write($"{array[i]} ");
}
foreach (var number in array)
{
if (number == currentNumber)
{
currentAmountOfRepetitions++;
}
else
{
currentAmountOfRepetitions = 1;
currentNumber = number;
}
if (currentAmountOfRepetitions > amountOfRepetitions)
{
amountOfRepetitions = currentAmountOfRepetitions;
repeatingNumber = currentNumber;
}
}
Console.WriteLine($"\nЧисло {repeatingNumber} повторяется больше всех, количество повторений - {amountOfRepetitions}.");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment