Determine if a given number is a palindrome or not

Write a program to determine if a given number is a palindrome or not. A palindromic number is a number that remains the same when its digits are reversed. Like 16461, for example, it is “symmetrical”.


We know that even if we reverse a palindrome number, it’s value will not change. This forms the idea behind proposed solutions. If the given number is equal to its reverse, then the number is palindrome else it is not palindrome number.

Iterative version –


Download   Run Code


Recursive version (in C++) –


Download   Run Code


We can also easily merge reverse() and isPalindrome() functions into one.


Download   Run Code

Please note that use of static variables is not recommended. Instead, we can pass the variables as argument to the isPalindrome() function.

Thanks for reading.

Please use ideone or C++ Shell or any other online compiler link to post code in comments.
Like us? Please spread the word and help us grow. Happy coding 🙂

Leave a Reply

Notify of