• + 0 comments

    In C:

    #include <stdio.h>
    #include <string.h>
    #include <math.h>
    #include <stdlib.h>
    #include <ctype.h>
    
    int main() {
    
        /* Enter your code here. Read input from STDIN. Print output to STDOUT */
        /* When accepting characters, maintain an array of integers 0 - 9. An index of an array denotes the digit itself and the value
        denotes the frequency of that index/digit */
        
        int arr[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
        char ch;
        int idx = 0;
        
        while((ch = getchar()) != '\n' && ch != EOF){
            if(isdigit(ch)){
                idx = ch - '0';  /* Need to subtract '0' (48 in ASCII) to get actual value of a digit */
                arr[idx]++;
            }
        }
        
        for(int i = 0; i < 10; ++i){
            printf("%d ", arr[i]);
        }
        printf("\n");
            
        return 0;
    }