Object:-Write a Program to find the frequency of characters.
char str, ch;
int i, frequency = 0;
printf("Enter a string: ");
printf("Enter a character to find the frequency: ");
for(i = 0; str[i] != ''; ++i)
if(ch == str[i])
printf("Frequency of %c = %d", ch, frequency);
Enter a string: CseWorldOnline
Enter a character to find the frequency: e
Frequency of e = 2
- In this program, the string entered by the user is stored in variable str.
- Then, the user is asked to enter the character whose frequency is to be found. This is stored in variable ch.
- Now, using the for loop, each character in the string is checked for the entered character.
- If, the character is found, the frequency is increased. If not, the loop continues.
- Finally, the frequency is printed.