Count consecutive pairs of same elements | C # implementation of the approach ; Function to return the count of consecutive elements in the array which are equal ; If consecutive elements are same ; Driver Code
using System ; class GfG { static int countCon ( int [ ] ar , int n ) { int cnt = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( ar [ i ] == ar [ i + 1 ] ) cnt ++ ; } return cnt ; } public static void Main ( ) { int [ ] ar = { 1 , 2 , 2 , 3 , 4 , 4 , 5 , 5 , 5 , 5 } ; int n = ar . Length ; Console . WriteLine ( countCon ( ar , n ) ) ; } }