Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

c program to find the frequency of characters in a string

#include <stdio.h>
int main() {
    char str[1000], ch;
    int count = 0;

    printf("Enter a string: ");
    fgets(str, sizeof(str), stdin);

    printf("Enter a character to find its frequency: ");
    scanf("%c", &ch);

    for (int i = 0; str[i] != ''; ++i) {
        if (ch == str[i])
            ++count;
    }

    printf("Frequency of %c = %d", ch, count);
    return 0;
}
Source by www.programiz.com #
 
PREVIOUS NEXT
Tagged: #program #find #frequency #characters #string
ADD COMMENT
Topic
Name
9+6 =