Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Подмассив_повторений_чисел
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- int currentCounter = 1;
- int temporaryResult = 0;
- int maxLength = 0;
- int repeatNumber = 0;
- int arrayLength = 30;
- int minRandomNumber = 0;
- int maxRandomNumber = 5;
- int[] array = new int[arrayLength];
- Random random = new Random();
- for (int i = 0; i < array.Length; i++)
- {
- array[i] = random.Next(minRandomNumber, maxRandomNumber);
- Console.Write(array[i] + " ");
- }
- for (int i = 1; i < array.Length; i++)
- {
- if (array[i] == array[i - 1])
- {
- currentCounter++;
- if (maxLength < currentCounter)
- {
- maxLength = currentCounter;
- repeatNumber = temporaryResult;
- }
- temporaryResult = array[i];
- }
- else
- {
- currentCounter = 1;
- }
- }
- if (maxLength >= currentCounter)
- {
- Console.WriteLine($"\nЧисло {repeatNumber} повторяется {maxLength} раз подряд");
- }
- else
- {
- Console.WriteLine("Нет повторений");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement