fork download
  1. #include <stdio.h>
  2.  
  3. int main(int argc, char * argv[]) {
  4. int input = atoi("31344842");
  5. int n = input;
  6. int digit_count = 0;
  7. while(n!=0) //count amount of digits in input
  8. {
  9. digit_count++;
  10. n /= 10;
  11. }
  12. int digit_array[digit_count]; //create array for digits
  13.  
  14. int i = digit_count;
  15. while(i!=0) //assign digits to array elements
  16. {
  17. digit_array[i-1] = input % 10;
  18. input /= 10;
  19. i--;
  20. }
  21.  
  22. //count number of times a digit has appeared
  23. int digit_amount[10] = {0,0,0,0,0,0,0,0,0,0};
  24. int digit = 0;
  25. while(digit<10)
  26. {
  27. int j = 0;
  28. while(j <= digit_count)
  29. {
  30. if(digit_array[j] == digit)
  31. {
  32. digit_amount[digit]++;
  33. }
  34. j++;
  35. }
  36. digit++;
  37. }
  38. //final output
  39. printf("Repeated digits:\n");
  40. int k = 0;
  41. while(k<10)
  42. {
  43. if(digit_amount[k] >= 2)
  44. {
  45. printf("\"%i\" occurs %i times.\n",k,digit_amount[k]);
  46. }
  47. k++;
  48. }
  49. return 0;
  50. }
  51.  
Success #stdin #stdout 0s 2156KB
stdin
Standard input is empty
stdout
Repeated digits:
"3" occurs 2 times.
"4" occurs 3 times.