codescracker


c

C Program to Find Frequency of Character in String



« Previous Program Next Program »


Find Frequency of Character in String in C

To find the frequency or occurrence of a particular characters present in the string or sentence in C programming, you have to ask to the user to enter the string. Now start searching for that character and increase the number of presence and display the frequency of character present in the string

C Programming Code to Find Frequency of Character in String

Following C program ask to the user to enter a string and a character to find the frequency of the entered character in the string :

/* C Program - Find Frequency of Character in String */
		
#include<stdio.h>
#include<conio.h>
void main()
{
	clrscr();
	int i, count=0;
	char str[1000], ch;
	printf("Enter the String : ");
	gets(str);
	printf("Enter a character to find frequency : ");
	scanf("%c",&ch);
	for(i=0; str[i]!='\0'; i++)
	{
		if(ch==str[i])
		{
			count++;
		}
	}
	printf("Frequency of the character %c = %d",ch, count);
	getch();
}

When the above c program is compile and executed, it will produce the following result:

c program find frequency of character

Same Program in Other Programming Language

You may also like same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test