Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Random random = new Random();
- int arrayLength = 30;
- int minimumNumberInArray = 7;
- int maximumNumberInArray = 9;
- int[] array = new int[arrayLength];
- int maximalRepeatingNumber = 0;
- int maximalCountOfRepeating = 0;
- int repeatingNumber = 0;
- int countOfRepeating = 0;
- Console.WriteLine($"Одномерный массив с длиной {arrayLength}:");
- for (int i = 0; i < array.Length; i++)
- {
- array[i] = random.Next(minimumNumberInArray, maximumNumberInArray + 1);
- Console.Write(array[i] + " ");
- }
- Console.WriteLine();
- for (int i = 0; i < array.Length; i++)
- {
- if (i > 0)
- {
- if (array[i] == repeatingNumber)
- {
- countOfRepeating++;
- }
- else
- {
- repeatingNumber = array[i];
- countOfRepeating = 1;
- }
- }
- else
- {
- repeatingNumber = array[i];
- countOfRepeating = 1;
- }
- if (countOfRepeating > maximalCountOfRepeating)
- {
- maximalCountOfRepeating = countOfRepeating;
- maximalRepeatingNumber = array[i];
- }
- }
- Console.WriteLine($"Число {maximalRepeatingNumber} повторяется подряд больше всего раз: {maximalCountOfRepeating}");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement