To Calculate the Frequency of given string
Code:
#include<iostream>
#include<conio.h>
#include<stdio.h>
using namespace std;
void main()
{
char str[100], ch;
int i, fre= 0;
cout<<"Enter a string: ";
gets(str);
cout<<"Enter a character to find
the frequency:";
cin>>ch;
for(i = 0; str[i] != '\0';
++i)
{
if(ch == str[i])
++fre;
}
cout<<"frequency
of "<<str<<"is:"<<fre;
getch
Output: