Check for repeated digits!
OK this code works to display one of the numbers that would be repeated. However I need to display all the numbers that may be repeated. Would I need to incorporate a printf function somewhere in the loop?
Code:
#include <stdio.h>
#define TRUE 1
#define FALSE 0
typedef int Bool;
main ()
{
Bool digit_seen[10] = {0};
int digit = 0;
int display_digit = 0;
long int n = 0;
printf("Enter a number: ");
scanf("%ld", &n);
while (n > 0)
{
digit = n % 10;
if (digit_seen[digit])
{
display_digit = digit;
break;
}
digit_seen[digit] = TRUE;
n /= 10;
}
if (n > 0)
printf ("Digits repeated are: %ld\n\n", display_digit);
else
printf("No repeated digit\n\n");
return 0;
}