What are Palindrome numbers?
Palindrome numbers are those whose reverse are identical to the number itself.
For example: 121, 13431, 999 are examples of palindrome numbers. Zero is a palindrome number.
- Palindrome numbers from 1-10 : 9
- Palindrome numbers from 1-100: 18
- Palindrome numbers from 1-1000 : 108
- Palindrome numbers from 1-10000 : 198
How to find whether a number is palindrome or not
Follow these steps to find whether a number is palindrome or not
- You can iterate the number simultaneously from first position to last position. Keep matching until both positions merge
- Second option is to reverse the number, and compare number with its reverse
How to find whether a number is palindrome or not in C++
Here is a detailed program to find whether number is a palindrome or not
#include <iostream>
using namespace std;
int
main ()
{
int n, num, l, r = 0;
cout << "Enter any number: ";
cin >> num;
n = num;
do
{
l = num % 10;
r = (r * 10) + l;
num = num / 10;
}
while (num != 0);
cout << "The reverse of given number is: " << r << endl;
if (n == r)
{
cout << "It is palindrome." << endl;
}
else
{
cout << "It is not palindrome." << endl;
}
return 0;
}
Contributor
This code is contributed by Mr Omkar Tukaram Ghate. Mr Omkar is currently final year Computer Science student from KIT College of Engineering.
End note
In this article, we have covered how to find palindrome in a number in C++. This question is very important from placement interview perspective.
If you have any confusion regarding this article, please do write in discussion thread below. You can also mail us to info@xamnation.com.
Founder, Xamnation.com
Graduate from IIT Delhi and IIM Kozhikode
14+ years in Education sector, working with government, schools, colleges, edtech startups and preschools
Mentored and coaching 100s of students in guiding right courses, right tutoring, and right career path

