HackerRank C- Digit Frequency




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



  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <math.h>
  4. #include <stdlib.h>
  5. int main() {
  6. char str[1000000];
  7. scanf("%s",str);
  8. int i=0,count=0,j=0,k=0;
  9. char a[10]="0123456789";
  10. int len=strlen(str);
  11. int b[10]={0};
  12. for(i=0;i<len;i++)
  13. {
  14. for(j=0;j<len;j++)
  15. {
  16. if(str[j]==a[k])
  17. {
  18. count++;
  19. }
  20. }
  21. b[k]=count;
  22. count=0;
  23. k++;
  24. }
  25. for(i=0;i<10;i++)
  26. {
  27. printf("%d ",b[i]);
  28. }
  29. return 0;
  30. }
Please click on the like button if it worked

Solution not working or have any suggestions? Please send an email to [email protected]


donate a cup of tea :)


Join Our Facebook Group

Share this solution






codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube