Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace HomeWork
- {
- internal class Program
- {
- public static void Main(string[] args)
- {
- int[] numbers = new int[30];
- int minRandomValue = 0;
- int maxRandomValue = 5;
- int maxSequenceLength = 1;
- int currentSequenceLength = 1;
- int numberWithMaxSequence = 0;
- Random random = new Random();
- Console.WriteLine("Исходный массив:");
- for (int i = 0; i < numbers.Length; i++)
- {
- numbers[i] = random.Next(minRandomValue, maxRandomValue + 1);
- Console.Write(numbers[i] + " ");
- }
- Console.WriteLine();
- for (int i = 1; i < numbers.Length; i++)
- {
- if (numbers[i] == numbers[i - 1])
- {
- currentSequenceLength++;
- if (currentSequenceLength > maxSequenceLength)
- {
- maxSequenceLength = currentSequenceLength;
- numberWithMaxSequence = numbers[i];
- }
- }
- else
- {
- currentSequenceLength = 1;
- }
- }
- Console.WriteLine($"\nЧисло {numberWithMaxSequence} повторяется подряд {maxSequenceLength} раз.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement