Wednesday, 16 March 2011

Code 9: Technique to check whether a number is palindrome.

Problem Description:       
A palindromic number or numeral palindrome is a 'symmetrical' number like 16461, that remains the same when its digits are reversed. Now we need to check whether a number given by the user is a palindrome.Let us take the input number to be checked in a variable n. Next we copy n to another variable m as m=n. Now we extract the last digit of n and save it in a variable r and by using the mathematical relation for formation of a number s=s*r+10, we from a new number which is ultimately just the reverse of the given number n. After the formation of the number,we check whether the actual number m is equal to the reversed number s.  If so,the number is a palindrome else not.



No comments:

Post a Comment