Q:

C++ program to find the frequency of a character in a string using Count Array

0

C++ program to find the frequency of a character in a string using Count Array

Through this program our aim is to see the implementation (how it works) of count array and its use.

In general, the solution of this problem can be achieved by a simple program as:

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include<iostream>
#include<cstring>
using namespace std;

int main()
{ 
	string s;
	char k; int i,c=0;

	cout<<"Enter String:";
	cin>>s;
	cout<<"Enter Character(a-z) : ";
	cin>>k;

	for(i=0;i<s.size();i++)     // size() return the size of the string   
	{ 
		if(s[i]==k)             /*here we check for each string element,if string element s[i] is 
		equalto character k then increase c by 1.*/
		c++;
	}
	cout<<k<<" occurs "<<c<<" times"<<endl;
	return 0;
}

Output

Enter String:IncludeHelp
Enter Character(a-z) : l
l occurs 2 times

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Most popular and Searched C++ solved programs with Explanation and Output

Similar questions


need a help?


find thousands of online teachers now
C++ program to print a spiral matrix... >>
<< C++ program to find factorial of large numbers usi...