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.
Runtime Input :
ksrct r
Output :
1
#include <stdio.h>
int freq_of_char(char* str, char ch) {
int count = 0;
while (*str) {
if (*str == ch) {
count++;
}
str++;
}
return count;
}
int main() {
char str[256];
char ch;
scanf("%s", str);
scanf(" %c", &ch);
int frq = freq_of_char(str, ch);
printf("%d\n", frq);
return 0;
}
Comments
Leave a comment