Program to count the frequency of a given letter in a string

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

    void main ( )
    {
        char a [20], ch ;
        int i , count ;
        cout<< "\n Enter a String : " ;
        cin>>a;
         cout<<"\nEnter a character to check its frequency in given string :";
           cin>>ch;
        i = 0 ;
           while (a[i]!='\0')
        {
            if ( ch == a [ i ] )
                count = count +1 ;
            i = i + 1 ;
         }
         cout<< "\nFrequency of given letter is "<<count ;
         getch ( ) ;
    }

0 comments:

Post a Comment

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|