Advertisement
JohnJuly

Homework24

Dec 2nd, 2023 (edited)
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.32 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Homework_24
  8. {
  9.     internal class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int[] numbers = new int[30] { 2, 2, 4, 5, 6, 7, 8, 4, 3, 3, 3, 6, 7, 8, 8, 8, 8, 9, 0, 2, 3, 6, 1, 6, 7, 4, 4, 6, 9, 0 };
  14.             int repeatCount = 1;
  15.             int maxRepeatCount = 0;
  16.             int numberMaxRepeat = 0;
  17.  
  18.             for (int i = 0; i < numbers.Length; i++)
  19.             {
  20.                 Console.Write(numbers[i] + " | ");
  21.             }
  22.  
  23.             for (int i = 0; i < numbers.Length - 1; i++)
  24.             {
  25.                 if (numbers[i] == numbers[i + 1])
  26.                 {
  27.                     repeatCount++;
  28.                 }
  29.                 else
  30.                 {
  31.                     repeatCount = 1;
  32.                 }
  33.  
  34.                 if (repeatCount > maxRepeatCount )
  35.                 {
  36.                     maxRepeatCount = repeatCount;
  37.                     numberMaxRepeat = numbers[i];
  38.                 }
  39.             }
  40.  
  41.             Console.WriteLine($"\nЧисло которое повторяется больше всего раз: {numberMaxRepeat}, количество его повторений: {maxRepeatCount}");
  42.         }
  43.     }
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement