TheFestFever.com

Our aim is to connect students from campuses all over Delhi by making them aware of all Technical, Cultural, Management fests, workshops, Seminars organized by every college in Delhi.

Join Us Now

Program 31: Write a C++ program to print the alphabet of a string which repeats maximum times.

#include<iostream>
#include<string.h>
using namespace std;

void dublicate(string str,int &size)
{
	for(int i=0;i<size;i++)
	{
		for(int j=i+1;j<size;j++)
		{
			if(str[i]==str[j])
			{
				for(int k=j+1;k<size;k++)
				{
					str[k-1]=str[k];
				}
				size--;
			}
		}
	}
}

int main()
{
	string str,str1;
	cout<<"\nenter a string : ";
	cin>>str;
	str1=str;
	int size=str.length(),size1=size;
	dublicate(str1,size1);
	int arr[size1],max=0,pos=0;

	for(int i=0;i<size1;i++)
	{
		int count=0;
		for(int j=0;j<size;j++)
		{
			if(str1[i]==str[j])
			count++;
		}
		arr[i]=count;
		if(count>max)
		{
			max=count;
			pos=i;
		}
	}
	cout<<"\nAlphabet "<<str1[pos]<<" is repeated maximum times i.e. "<<max;
	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.