If you want to write a C++ program to check whether the entered number is palindrome number or not, then this tutorial is specially designed for you. Please keep your close attention in this post as I am going to share a C++ program to check palindrome number while executing below C++ program.
The palindrome number is a number which is equal to it’s reversed number, like if the user entered 12321, then the reversed number of entered number is same as the original number so that this number is a palindrome number.
1 2 3 | //example of a palindrome number Original number: 12321 Reversed number: 12321 |
if you want to check the palindrome number, then first you need to reserve the entered number and then check if the reversed number and entered number is same, then that number is a palindrome number. Below program will check whether entered number is a palindrome number or not.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | #include <iostream> using namespace std; int main() { int n, num, digit, rev = 0; cout << "Enter a positive number: "; cin >> num; n = num; do { digit = num % 10; rev = (rev * 10) + digit; num = num / 10; } while (num != 0); cout << " Reverse number is: " << rev << endl; if (n == rev) cout << " This number is a palindrome number"; else cout << " This number is not a palindrome number"; return 0; } |
//Frist try
Enter a positive number: 151
Reverse number is: 151
This number is a palindrome number.
#Second try
Enter a positive number: 1345
Reverse number is: 5431
This number is not a palindrome number.
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.
Article Tags: c++ program to check given number is palindrome or not, C++ program to check palindrome number, check for palindrome, check for palindrome number