fastread homefastrread library fastread menu

C : Find the Frequency of Characters in a String

Tutorial by:Manisha Dubey      Date: 2016-06-17 04:31:08

❰ Previous Next ❱

This program asks user to enter a string and a character and this program checks how many times that character is repeated in the string entered by user.

Source Code to Find the Frequency of Characters


#include <stdio.h>
int main(){
   char c[1000],ch;
   int i,count=0;
   printf("Enter a string: ");
   gets(c);
   printf("Enter a character to find frequency: ");
   scanf("%c",&ch);
   for(i=0;c[i]!='\0';++i)
   {
       if(ch==c[i])
           ++count;
   }
   printf("Frequency of %c = %d", ch, count);
   return 0;
}

Output

Enter a string: This website is awesome.
Enter a character to find frequency: e
Frequency of e = 4

❰ Previous Next ❱


C

Submit Your Thought, Tutorial, Articls etc.

Submit Your Information India's Number one online promotion website