C++ Program to input a string and a character. Print the frequency of the character within the string
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<process.h>
#include<stdio.h>
main()
{
clrscr();
char name[40],input;
int l=0,count=0;
cout<<"Enter any word "<<endl;
gets(name);
cout<<endl<<"Enter the character to print the frequency";
cin>>input;
l = strlen(name);
cout<<endl;
for (int a=0;a<l;a++)
{
if (name[a]==input) count = count + 1;
}
cout<<endl<<"The frequency of "<<input<<" is "<<count<<endl;
getch();
return 0;
}
Related Posts : C++ Programs
0 comments:
Post a Comment