In: Computer Science
This is for C programming.
Suppose one string is defined for a sentence with maximum 100 characters.
Write a method that prints maximum occurring characters in the input string and its frequency. For example, if input string is "this is testt", your code should print 't' : 4.
Thank you.
`Hey,
Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries
#include<stdio.h>
void printMax(char s[],int n)
{
int i,arr[26];
for(i=0;i<26;i++)
arr[i]=0;
for(i=0;i<n;i++)
{
if(s[i]>='a'&&s[i]<='z')
{
arr[s[i]-'a']++;
}
else if(s[i]>='A'&&s[i]<='Z')
{
arr[s[i]-'A']++;
}
}
int ind=0,max=arr[0];
for(i=0;i<26;i++)
{ if(max<arr[i])
{
max=arr[i];
ind=i;
}
}
printf("'%c' : %d\n",(ind+'a'),arr[ind]);
}
int main(){
char s[100];
printf("Enter string: ");
gets(s);
printMax(s,strlen(s));
return 0;
}
Kindly revert for any queries
Thanks.