ranee

массив повторение

Sep 7th, 2022 (edited)
1,035
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.67 KB | None | 0 0
  1. int[] array = new int[] { 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 8 };
  2. int counter = 1;
  3. int rememberNumner = 0;
  4. int repetitionСouneter = 0;
  5.  
  6. foreach (var numbers in array)
  7. {
  8.     Console.Write($"{numbers} ");
  9. }
  10.  
  11. for (int i = 0; i < array.Length - 1 ; i++)
  12. {
  13.     if(array[i] == (array[i + 1]))
  14.     {
  15.         counter++;
  16.     }
  17.     else if (counter > repetitionСouneter)
  18.     {
  19.         repetitionСouneter = counter;
  20.         rememberNumner = array[i];
  21.         counter = 1;
  22.     }
  23.     else
  24.     {
  25.         counter = 1;
  26.     }
  27. }
  28.  
  29. Console.WriteLine($"\nЧисло {rememberNumner} повторяется {repetitionСouneter}");
  30.  
Advertisement
Add Comment
Please, Sign In to add comment