• + 0 comments

    total beginner here, dont judge but this the code that i wrote, ik it is super long but its the only one i could think of, i tried running it on vs code and it did give the required output but it didnt pass in hackerrank, can someone tell why

    include

    include

    include

    include

    int main() { char ch[30]; int count = 0; int c;

    fgets(ch, 30, stdin); // Read input
    
    // Count '0'
    count = 0;
    c = '0';
    for (int i = 0; i < strlen(ch); i++) {
        if (ch[i] == c) {
            count++;
        }
    }
    printf("%d ", count);
    
    // Count '1'
    count = 0;
    c = '1';
    for (int i = 0; i < strlen(ch); i++) {
        if (ch[i] == c) {
            count++;
        }
    }
    printf("%d ", count);
    
    // Count '2'
    count = 0;
    c = '2';
    for (int i = 0; i < strlen(ch); i++) {
        if (ch[i] == c) {
            count++;
        }
    }
    printf("%d ", count);
    
    // Count '3'
    count = 0;
    c = '3';
    for (int i = 0; i < strlen(ch); i++) {
        if (ch[i] == c) {
            count++;
        }
    }
    printf("%d ", count);
    
    // Count '4'
    count = 0;
    c = '4';
    for (int i = 0; i < strlen(ch); i++) {
        if (ch[i] == c) {
            count++;
        }
    }
    printf("%d ", count);
    
    // Count '5'
    count = 0;
    c = '5';
    for (int i = 0; i < strlen(ch); i++) {
        if (ch[i] == c) {
            count++;
        }
    }
    printf("%d ", count);
    
    // Count '6'
    count = 0;
    c = '6';
    for (int i = 0; i < strlen(ch); i++) {
        if (ch[i] == c) {
            count++;
        }
    }
    printf("%d ", count);
    
    // Count '7'
    count = 0;
    c = '7';
    for (int i = 0; i < strlen(ch); i++) {
        if (ch[i] == c) {
            count++;
        }
    }
    printf("%d ", count);
    
    // Count '8'
    count = 0;
    c = '8';
    for (int i = 0; i < strlen(ch); i++) {
        if (ch[i] == c) {
            count++;
        }
    }
    printf("%d ", count);
    
    // Count '9'
    count = 0;
    c = '9';
    for (int i = 0; i < strlen(ch); i++) {
        if (ch[i] == c) {
            count++;
        }
    }
    printf("%d ", count);
    
    return 0;
    

    }