Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace homeWorkSubarrayOfRepetitionsOfNumbers
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- Random random = new Random();
- int maxValue = 1;
- int minValue = 0;
- int sizeNumbers = 30;
- int maxCount = 1;
- int currentCount = 1;
- int[] numbers = new int[30];
- for (int i = 0; i < numbers.Length; i++)
- {
- numbers[i] = random.Next(minValue, maxValue + 1);
- }
- int currentNumber = numbers[0];
- Console.Write($"Массив: ");
- for (int i = 0; i < numbers.Length; i++)
- {
- Console.Write($"{numbers[i]} ");
- }
- for (int i = 1; i < numbers.Length; i++)
- {
- if (numbers[i] == numbers[i-1])
- {
- currentCount++;
- }
- else
- {
- if (currentCount > maxCount)
- {
- maxCount = currentCount;
- currentNumber = numbers[i - 1];
- }
- currentCount = 1;
- }
- }
- if (currentCount > maxCount)
- {
- maxCount = currentCount;
- currentNumber = numbers[numbers.Length - 1];
- }
- Console.WriteLine($"\nЧисло {currentNumber} повторяется {maxCount} раз подряд.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement