- Home
- Course Category
- Course Result
- Course Detail
Hot Line: 0124-2383121
Course Introduction
Programs for practice
To find the frequency of character or count occurrence of character in string in C++ programming, you have to ask to the user to enter the string, again ask to enter the character to find the frequency of that character (or to count the occurrence of character) in given string. After finding the frequency of the character, display the result on the output screen as shown here in the following program.
Source Code: Find Frequency of Character in String
/* C++ Program - Find Frequency of Character in String */ #include<iostream.h> #include<conio.h> #include<stdio.h> void main() { clrscr(); int i, count=0; char str[1000], ch; cout<<"Enter the String : "; gets(str); cout<<"Enter a character to find frequency : "; cin>>ch; for(i=0; str[i]!='\0'; i++) { if(ch==str[i]) { count++; } } cout<<"Frequency of the character "<<ch<<" = "<<count; getch(); }Output
Enter the String : hello and welcome to blazingminds Enter a character to find frequency : a Frequency of the character a = 2