Please click on 1-2 Ads to keep this website's Study Material FREE and regularly Updated.

Program 15: Write a C++ program to return the number of clumps in a given array.

#include<iostream>
using namespace std;

int main()
{
	int size=0,clumps=0;
	cout<<"\nenter the size of an array : ";
	cin>>size;
	int arr[size];
	cout<<"\nenter array elements : ";

	for(int i=0;i<size;i++)
	{
		cin>>arr[i];
	}

	for(int i=0;i<size-1;i++)
	{
		int temp=arr[i],j=i+1,flag=0;
		while((arr[j]==temp)&&(j<size))
		{
			flag=1;
			j++;
		}
		if(flag==1)
		clumps++;
		i=j-1;
	}
	cout<<"\ntotal no. of clumps : "<<clumps;	
	return 0;
}



If you have any suggestion or found any error in the above program, then do let us know at [email protected] or just comment below.