Write a code which will check whether the number is palindrome or not.PS: Don not convert a number into string .
SOLUTION
bool IsPalindrome( int n){
int a=n, b=0;
while( n > 0){
b = b*10 + n%10;
n /= 10;
}
if ( a == b)
return true;
return false;
}
Subscribe to:
Post Comments (Atom)

4 comments:
reverse=0
temp=number
while(number > 0)
1.extract last digit using mod 10
2.divide number by 10
3.reverse=reverse * 10 + last digit
if temp==reverse
palindrome
else
not palindrome
now we know how to check the no. is palindrome or not,
lets solve this problem:
Given a no. which is palindrome, find the next palindrome.
For example input: 808
output: 818
@above:
Your approach is right.
For your question: go to the middle element increment it by 1. ( if digits are odd)
for even digits increment both middle digits by 1.
however, special care is to be taken if middle digit is 9.
hmmm, correct
Post a Comment