Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Homework24
- {
- class Program
- {
- static void Main()
- {
- int[] array = new int[30];
- Random random = new Random();
- int repeatedNumber = 0;
- int numberOfRepetitions = 1;
- int maxNumberOfRepetitions = 0;
- Console.WriteLine("Исходный массив:");
- for (int i = 0; i < array.Length; i++)
- {
- array[i] = random.Next(0, 30);
- Console.Write(array[i] + " ");
- }
- for (int i = 0; i < array.Length - 1; i++)
- {
- if (array[i] == array[i + 1])
- {
- numberOfRepetitions++;
- }
- else
- {
- numberOfRepetitions = 1;
- }
- if (numberOfRepetitions > maxNumberOfRepetitions)
- {
- maxNumberOfRepetitions = numberOfRepetitions;
- repeatedNumber = array[i];
- }
- }
- Console.WriteLine($"\n\nЧисло, которое повторяется наибольшее количество раз подряд: {repeatedNumber}.\nСколько раз оно повторяется подряд: {maxNumberOfRepetitions}.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement