Search
 
SCRIPT & CODE EXAMPLE
 

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;
        }
    }
}
Comment

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;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: function overloading in cpp 
Cpp :: binary add using strings 
Cpp :: print all even number using for loop c++ 
Cpp :: c++ error 0xC0000005 
Cpp :: a function to create double quotes for alphabet in c++ 
Cpp :: c++ short hand if else 
Cpp :: friend class c++ 
C :: C output color font 
C :: how to create random integers from a specific range in c language 
C :: rename c 
C :: pygame detect click 
C :: arduino serial read write structure 
C :: imprimir valor no octave 
C :: execution time of c program 
C :: send http request in C 
C :: prime numbers c 
C :: postgres random select 
C :: get current used proxy windows 7 
C :: const godot gdscript 
C :: how to empty string in c 
C :: c execute shell command 
C :: how to make a linked list in c 
C :: c program to print the multiplication table 
C :: add a item to cart woocomerce with quantity 
C :: putchar in c 
C :: sqlserver insert with set identity 
C :: c program to find the frequency of characters in a string 
C :: concatenate two strings without standard library in C 
C :: declare string in c 
C :: apt-mark remove hold 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =