#include <stdio.h>
int main() {
int N,A,B;
while(N>=0)
{
A = N%10;
B = (N/10)%10;
if(A == B)
{
printf("YES");
return 0;
}
N = N/10;
}
if(A != B)
printf("NO");
return 0;
}
This code attempts to check if a number has two adjacent equal digits, but it has several issues. The variable N is used without being initialized, so its value is unpredictable. The loop condition checks N >= 0, but N is never given a starting value from user input. Also, the logic for comparing digits and printing results may not work correctly for all cases.
- You need to read a value into N before using it, for example with scanf. Without initialization, the program behavior is undefined.
- The loop condition N >= 0 will cause problems when N becomes 0, because 0 has only one digit, but your code still tries to extract two digits. Consider what happens when N is a single-digit number.