#include <stdio.h>
int main() {
int n;
int num[10]={0};
scanf("%d",&n);
while(n>0){
int d=n%10;
n=n/10;
if(num[d]==1){
printf("YES");
return 0;
}
num[d]=1;
}
printf("NO");
return 0;
}
This code checks if a given integer has any repeated digit. It extracts each digit, records it in an array, and if a digit is seen again, it prints "YES" and stops. If no repetition is found, it prints "NO".
- The array `num` is declared with size 10, which is enough for digits 0-9, but the code does not handle the digit 0 correctly because `num[0]` is never set to 1 when a zero digit is encountered. Check the logic for when the digit is 0.
- The condition `if(num[d]==1)` will never be true for digit 0 because `num[0]` stays 0 throughout the loop. Think about how to mark that a zero digit has been seen.