Hello and asalam o alikum. I hope you all are enjoying good health by the grace of Allah Almighty.
Today I am here with another operation of string and in this program,I will find the frequency of characters in a string.It means this program will check how many times a specific character is repeated in the string entered by the user.
The reference of this blog is taken from the following link.
Below is the source code of this program.
Source code
#include <iostream>
#include <cstring>
using namespace std;
int main(){
char c[1000],ch;
int i,count=0;
cout << "Enter a string: ";
cin.getline(c, 1000);
cout << "Enter a character to find frequency: ";
cin >> ch;
for(i=0;c[i]!='\0';++i)
{
if(ch==c[i])
++count;
}
cout << "Frequency of " << ch << " = " << count;
return 0;
}
Output
.cstring header file
Remember that this header file defines several functions to manipulate C++ strings and arrays.
No comments:
Post a Comment