Microsoft Interview Question Software Engineer / Developers
0of 0 votesCheck whether the number is palindrome or not without using array?
Convert the 6 decimal system into 10 decimal system?
// 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;
}
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

reverse, compare.
- geniusxsy on November 09, 2009 Edit | Flag Replywhat is 6 decimal system??? base_6 representation?