C program to find the maximum occuring element in the string


#include <stdio.h>

int main() 
{
    char str[20];
    int i,cnt, max=1,temp=0,j;
    
    printf("enter the string\n");
    scanf("%[^\n]%*c",str);
    
    for(i=0;str[i]!='\0';i++)
    {   
     cnt=1;
    for(j=i+1;str[j]!='\0';j++)
    { 
        if(str[i]==str[j] && str[j]!='*' && str[j]!=' ')
        {
        cnt++;
        str[j]='*';
        }
    }
    if(cnt>max)
    {
    max=cnt;
    temp=i;
    }
    }
    printf("%c is the maximum occuring element with maximum number %d",str[temp],max);
    
    return 0;
}

Output:
enter the string
never give up
e is the maximum occuring element with maximum number 3