Header Ads Widget

Responsive Advertisement

Highest Frequency of A Character in A String


 

#include<stdio.h>
#include<string.h>
int main()
{
    char str[100];
    int count,maxCount=0,len;
    char maxRep;
    printf("Enter A String : ");
    fgets(str,100,stdin);
    len=strlen(str)-1;
    for(int i=0; i<len; i++)
    {   str[i]=tolower(str[i]);
        count=0;
        for(int j=0; j<len; j++)
        {
            if(str[i]==str[j])
            {
                count++;
            }
        }
        if(maxCount<count)
        {
            maxCount=count;
            maxRep=str[i];
        }
    }
    printf("The Maximum Occurance Character ' %c ' is Present ' %d ' times. ",maxRep, maxCount);
    return 0;
}


Post a Comment

0 Comments