C Online Compiler
Example: C Program to Find the Frequency of Characters in a String
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// C Program to Find the Frequency of Characters in a String #include <stdio.h> // It's the main function of the program int main() { char string[500], search_char; int string_count = 0; // Step-1 Take input any sentence up to 500 characters printf("Enter the string: "); fgets(string, sizeof(string), stdin); // Step-2 Enter a character to find printf("Enter a character to count it's frequency: "); scanf("%c", &search_char); // Step-3 Make iteration over the given sentence for (int i = 0; string[i] != '\0'; i++) { if (string[i] == search_char) { string_count += 1; } } // Step-4 Final output of the program printf("Frequency of '%c' is %d\n", search_char, string_count); return 0; }
hi this is my first program i
Output
Clear
ADVERTISEMENTS