Count Frequency of Characters in C++

Advertisements

Reverse String in C++ Concatenate Two String in C++

C++ program to Count Frequency of Characters

Frequency of character in any string means how many times a particular character is present in any string. For example; suppose we have string hitesh in this word h repeated 2 times, it is the frequency of h in string hitesh.

Count Frequency of Characters in C++

#include<iostream.h>
#include<stdio.h>
#include<conio.h>

 void main()
 {
   int i,count=0;
   char ch[20],c;
   clrscr();
   cout<<"Enter Any String: ";
   gets(ch);
   cout<<"Enter any Character form string: ";
   cin>>c;
   for(i=0;ch[i]!='\0';i++)
   {
   if(ch[i]==c)
   count++;
   }
   if(count==0)
   {
   cout<<"Given character not found";
   }
   else
   {
   cout<<"Repetition of " <<c<<" "<<count<<" times";
   }
   getch();
 }

Output

Enter any String: india
Enter any Character form string: i
Repetition of i 2 times

Reverse String in C++ Concatenate Two String in C++

Advertisements

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements