// Program to input a string and print the character with the
// maximum frequency in the string.
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<process.h>
#include<stdio.h>
#include<string.h>
main()
{
clrscr();
char name[40],ans;
int l=0,count=0,max=0;
cout<<"Enter any word "<<endl;
gets(name);
l = strlen(name);
cout<<endl;
for(int a=0;a<l;a++)
{
for (int b=0;b<l;b++)
{
if (name[a]==name[b] && name[a]!=' ')
count = count+1;
}
if (max<count)
{
max=count;
ans=name[a];
}
count=0;}
cout<<endl<<"The character with maximum frequency is ";
cout<<ans<<" with occurring "<<max<<endl;
getch();
return 0;
}
No comments:
Post a Comment