ahmed0saber

Frequency of a character in string in C++

Nov 13th, 2020
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.33 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     string str="C++ Programming is awesome";
  6.     char checkCharacter='a';
  7.     int count=0;
  8.     for (int i=0;i<str.size();i++)
  9.     {
  10.         if (str[i]==checkCharacter)
  11.         {
  12.             ++count;
  13.         }
  14.     }
  15.     cout<<"Number of "<<checkCharacter<<" = "<<count;
  16. }
Advertisement
Add Comment
Please, Sign In to add comment