Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

frequency of characters in a string in c++

#include<iostream>
using namespace std;
int main(){
    string a;
    cout<<"enter string ";
    getline(cin,a);
    int freq[256]={0};
    int b;
    for(int i=0;a[i]!='';i++){
        b=a[i];
        freq[b]++;
    }
    for(int i=0;i<256;i++)
    {
        if(freq[i]!=0){
            cout<<"The frequency of "<<char(i)<<" is "<< freq[i]<<endl;
        }
    }
}
 
PREVIOUS NEXT
Tagged: #frequency #characters #string
ADD COMMENT
Topic
Name
9+9 =