string, , consisting of alphabets and digits, find the frequency of each digit in the given string | HackerRank

 

Given a string, , consisting of alphabets and digits, find the frequency of each digit in the given string.
HackerRank

#include <stdio.h>

#include <string.h>

#include <math.h>

#include <stdlib.h>


int main() {


    int num [10] = {0};

    char s[100];

    scanf("%[^\n]s" ,s);

    for(int i = 0; i< strlen(s);i++){

        if(s[i] >= '0' && s[i] <= '9'){

            num[s[i] - '0']++;

        }

        

    }

    for(int i = 0;i<10;i++){

          printf("%d" ,num[i]);

    }

  

    

    return 0;

}

No comments: