fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main(int argc, char * argv[]) {
  5. char* input = "31344842";
  6. int digit_count = 0;
  7.  
  8. digit_count = strlen(input); //count amount of digits in input
  9.  
  10.  
  11. //count number of times a digit has appeared
  12. int digit_amount[10] = {0,0,0,0,0,0,0,0,0,0};
  13. int digit = 0;
  14. while(digit<10)
  15. {
  16. int count = 0;
  17. char* singleDigit[1];
  18. while(count <= digit_count)
  19. {
  20. // Subtracting the character 0 from a character will give you its real int value
  21. if((input[count] - '0') == digit)
  22. {
  23. digit_amount[digit]++;
  24. }
  25. count++;
  26. }
  27. digit++;
  28. }
  29. //final output
  30. printf("Repeated digits:\n");
  31. int k = 0;
  32. while(k<10)
  33. {
  34. if(digit_amount[k] >= 2)
  35. {
  36. printf("\"%i\" occurs %i times.\n",k,digit_amount[k]);
  37. }
  38. k++;
  39. }
  40. return 0;
  41. }
  42.  
  43.  
Success #stdin #stdout 0s 2156KB
stdin
Standard input is empty
stdout
Repeated digits:
"3" occurs 2 times.
"4" occurs 3 times.