Created
June 29, 2024 18:16
-
-
Save MagSosiq/90396009838a57a804e163692d473de5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Text; | |
namespace HW1 | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.InputEncoding = Encoding.Unicode; | |
Console.OutputEncoding = Encoding.Unicode; | |
Random random = new Random(); | |
int[] numbers = new int[30]; | |
int numbersCount = 1; | |
int maxNumbersCount = 1; | |
int repeatingNumber = numbers[0]; | |
Console.Write("Наш массив чисел: "); | |
for (int i = 0; i < numbers.Length; i++) | |
{ | |
numbers[i] = random.Next(0, 10); | |
Console.Write(numbers[i] + " "); | |
} | |
Console.WriteLine(); | |
for (int i = 0; i < numbers.Length - 1; i++) | |
{ | |
if (numbers[i] == numbers[i + 1]) | |
{ | |
numbersCount++; | |
} | |
else | |
{ | |
if (numbersCount > maxNumbersCount) | |
{ | |
maxNumbersCount = numbersCount; | |
repeatingNumber = numbers[i]; | |
} | |
numbersCount = 1; | |
} | |
} | |
if (numbersCount > maxNumbersCount) | |
{ | |
maxNumbersCount = numbersCount; | |
repeatingNumber = numbers[numbers.Length - 1]; | |
} | |
Console.WriteLine($"Число {repeatingNumber} повторяется {maxNumbersCount} раз подряд"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment