Sort by

recency

|

1182 Discussions

|

  • + 1 comment

    include

    include

    include

    include

    int main() {

    char s[100];
    int freq[10] = {0};
    scanf("%s",s);
    for(int i = 0; s[i] != '\0'; i++){
        if(s[i] >= '0' && s[i] <= '9'){
            freq[s[i]-'0']++;
        }
    }
    for(int i = 0; i<10; i++){
        printf("%d",freq[i]);
    }
    return 0;
    

    }

  • + 0 comments

    Here is Digit Frequency Solution in c - https://programmingoneonone.com/hackerrank-digit-frequency-solution-in-c.html

  • + 0 comments

    include

    include

    include

    include

    int main() {

    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  
    char s[1000];
    int freq[10] = {0}; 
    
    scanf("%[^\n]", s); 
    for (int i = 0; i < strlen(s); i++) {
        if (s[i] >= '0' && s[i] <= '9') {
            freq[s[i] - '0']++;
        }
    }
    
    for (int i = 0; i < 10; i++) {
        printf("%d ", freq[i]);
    }  
    return 0;
    

    }

  • + 0 comments

    int main() {

    char *s;
    int i, NumberCounter[10] = {0,0,0,0,0,0,0,0,0};
    s = malloc(1024 * sizeof(char));
    scanf("%[^\n]", s);
    
    
    for (i=0;s[i]!='\0';i++)
    {            
      if (isdigit(s[i]))              
         ++NumberCounter[s[i]-'0'];                    
    }
    
    for (i=0; i<10;i++)
      printf ("%d ", NumberCounter[i]);
    

    return 0; }

  • + 0 comments

    used the longest method possible😁😁

    include

    include

    include

    include

    include

    int main() {

    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  
    char str[1000];  
    scanf("%s",str);
    int a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,m=0,j=0;
    for(int i=0;i<strlen(str);i++){
        if (isdigit(str[i])){
            if (str[i]=='0'){
                a++;
            }
            if (str[i]=='1') {
                b++;
            }
            if (str[i]=='2'){
                c++;
            }
            if (str[i]=='3'){
                d++;
            }
            if (str[i]=='4'){
                e++;
            }
            if (str[i]=='5'){
                f++;
            }if (str[i]=='6'){
                g++;
            }if (str[i]=='7'){
                h++;
            }if (str[i]=='8'){
                m++;
            }if (str[i]=='9'){
                j++;
        }
    }
    }
    printf("%d %d %d %d ",a,b,c,d);
    printf("%d %d %d %d %d %d",e,f,g,h,m,j);
    return 0;
    

    }