C Programming
Computer Programming

C program to Find the frequency of a character in a string



Write a program in C to Find the frequency of a character in a string

\* C program to Find the frequency of a character in a string *\

# include < stdio.h >
# include < conio.h >
int   main( )
{

char str[1000], ch ;
int i, frequency = 0 ;
printf("\n Enter a string : ") ;
gets(str) ;
printf("\n Enter a character to find the frequency: ") ;
scanf("%c",&ch) ;
for(i = 0; str[i] != '\0'; ++i)
{
      if(ch == str[i])
            ++frequency ;
}
printf("\n Frequency of %c = %d", ch, frequency) ;
return 0 ;

}

Output of Program :

Output of C program to Find the frequency of a character in a string