This program checks whether any of the digits in a number entered by the user appear more than once. What I still can't understand is the code inside "if" statement. What's the idea behind that? We get each of the digits at a time, then that digit is used as an index for the array named "digit_seen"... and then digit_seen[digit] = true... It's confusing to me. Can anyone please explain this program clearly??? Thanks a lot.
Code:#include<stdio.h> #include<stdbool.h> int main(void) { bool digit_seen[10] = {false}; int digit; long n; printf("Enter a number: "); scanf("%ld", &n); while(n > 0) { digit = n % 10; if(digit_seen[digit]) break; digit_seen[digit] = true; n /= 10; } if(n > 0) printf("Repeated digit\n"); else printf("No repeated digit\n"); return 0; }