Tuesday, 5 April 2016

Program to find frequency of characters in a string C++ Problem Solution.


Solution:

#include<bits/stdc++.h>
using namespace std;
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main(){

    string str;
    char ch;
    int cnt = 0;

    cout << "Enter a string: ";
    getline(cin,str);
    cout << "Enter a character to find frequency: ";
    cin >> ch;
    for(int i = 0; i < str.size(); i++)if(ch == str[i])cnt++;

    cout << "Frequency of " << ch << " = " << cnt << endl;;
    return 0;
}

No comments:

Post a Comment