Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

frequency of characters in a string in c++

#include <iostream>
using namespace std;
int main() {
   char str[100] = "this string contains many alphabets";
   char c = 'a';
   int count = 0;
   for(int i = 0; str[i] != ''; i++) {
      if(str[i] == c)
      count++;
   }
   cout<<"Frequency of alphabet "<<c<<" in the string is "<<count;
   return 0;
}
Source by www.tutorialspoint.com #
 
PREVIOUS NEXT
Tagged: #frequency #characters #string
ADD COMMENT
Topic
Name
9+4 =