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

Check user availability ajax   |   Php xampp installation   |   Java exception handling interview questions

QUOTES OF THE DAY

Eat to live, and not live for eat.

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER