How to find the frequency of a character in a string with C

1 Answer

0 votes
#include <stdio.h> 
  
int main(void)
{   
    char s[50] = "c c++ c# java python";
    int frequency = 0;
    char ch = 'c';

    for (int i = 0; s[i]; i++)
    {
       if (ch == s[i])
           frequency++;
    }

    printf("Frequency of the characters '%c' is: %d", ch, frequency);
      
    return 0;
}
  
          
/*
run:
       
Frequency of the characters 'c' is: 3
 
*/

 



answered May 25, 2017 by avibootz

Related questions

1 answer 112 views
1 answer 135 views
1 answer 112 views
1 answer 132 views
1 answer 150 views
...