• + 0 comments

    include

    int main() { char str[1000]; int digit_count[10] = {0};

    // Input string
    printf("Enter a string: ");
    scanf("%s", str);
    
    // Iterate through the characters of the input string
    for (int i = 0; i < strlen(str); i++) {
        if (str[i] >= '0' && str[i] <= '9') {
            int digit = str[i] - '0';
            digit_count[digit]++;
        }
    }
    
    // Print the frequency of each digit
    printf("Frequency of each digit from 0 to 9: ");
    for (int i = 0; i < 10; i++) {
        printf("%d ", digit_count[i]);
    }