pTutorial

New way to learn C programming

C program to count Frequency of Characters

This is a user defined c program to count the frequency of a particular character in an entered string. For example "php" is a string and frequency of p in this string is 2.

Frequency of character



#include <stdio.h>
#include <conio.h>
void main()
{
   char z[25],x;
   int i,k=0;
   
   printf(" please enter string :");
   gets(z);
   
   printf("a character: ");
   scanf("%c",&x);
   
   for(i=0;z[i]!='\0';++i)
   {
       if(x==z[i])
        k++;
   }
   
   printf("Total number of character is:%d\n",i);
   printf("Frequency of %c = %d", x, k);
   
}

Download C program to count characters frequency

Output of program

string concatenation | ptutorial

In this example first ask user for a string and then a character, simply check whether entered character is presented in the or not, if presented then increase one in the "k" variable and at last print the total number of sting and frequency of the entered character.

See Also

Mail function   |   Php introduction   |   Php upload image

QUOTES OF THE DAY

Beauty is truth, Truth beauty- That is all

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER