Design a C program to find the Frequency of Characters. 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 and display.
#include <stdio.h>
#include <string.h>
int main(){
char str[1000];
char character;
int frequency=0;
int i;
printf("Ente string: ");
gets(str);
printf("Enter the character whose frequency is to be found: ");
scanf("%c",&character);
for(i=0;i<strlen(str);i++){
if(character==str[i]){
frequency++;
}
}
printf("Frequency: %d\n\n",frequency);
getchar();
getchar();
return 0;
}
Comments
Leave a comment