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
#include <iostream> NEW_LINE using namespace std ; 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 ; } int main ( ) { int ar [ ] = { 1 , 2 , 2 , 3 , 4 , 4 , 5 , 5 , 5 , 5 } ; int n = sizeof ( ar ) / sizeof ( ar [ 0 ] ) ; cout << countCon ( ar , n ) ; return 0 ; }