Program to count frequency of characters


Prev Tutorial Next Tutorial

Program to find frequency of characters

Frequency of character in any string means how many times a particular character is present in any string.

Program to find frequency of characters

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

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

Output

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

Prev Tutorial Next Tutorial

Advertisements




Facebook Likes

Advertisements