Count the number of clumps in the given Array | C ++ program to calculate the number of clumps in an array ; Function to count the number of clumps in the given array arr [ ] ; Initialise count of clumps as 0 ; Traverse the arr [ ] ; Whenever a sequence of same value is encountered ; Return the count of clumps ; Driver Code ; length of the given array arr [ ] ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countClumps ( int arr [ ] , int N ) { int clumps = 0 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { int flag = 0 ; while ( arr [ i ] == arr [ i + 1 ] ) { flag = 1 ; i ++ ; } if ( flag ) clumps ++ ; } return clumps ; } int main ( ) { int arr [ ] = { 13 , 15 , 66 , 66 , 66 , 37 , 37 , 8 , 8 , 11 , 11 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << countClumps ( arr , N ) << ' ' ; return 0 ; }