## Microsoft Interview Question

Software Engineer / Developers```
// count the number of digits.
count=0;
while(n) {++count;n/=10}
// now compare digits
for(i=1;i<count/2;++i){
if(n/pow(10,count-i) != n % pow(10,i)
return false;
}
```

void palindrome(int n){

int reverse_n=0, int tempn=n;

while(n){

reverse_n*=10;

reverse_n+=n%10;

n/=10;

}

return tempn==reverse_n;

}

Algo:

1: convert the number into staring using itoa, ltoa or whatever suitable in-built function

2: take size of the string, n

3: then compare the i and n-i positions, increment i everytime till you reach the half

please correct me if i am wrong

void palindrome(int n){

- geniusxsy November 09, 2009int reverse_n=0, int tempn=n;

while(n){

reverse_n*=10;

reverse_n+=n%10;

n/=10;

}

return tempn==reverse_n;

}