C++ Program to Check Palindrome Number using While loop
ADVERTISEMENTS
C++ program to check palindrome number using while loop. In this article, you will learn that how to make a C++ program to check palindrome number using while loop.
What is Palindrome Number?
A palindrome is a case where if the reverse of any number will be matched correctly with its original integer number, It will be a palindrome.
Palindrome Number Formula
7997 == 7997 => a palindrome
Source Code
// C++ Program to Check Palindrome Number using While loop
#include <iostream>
using namespace std;
int main() {
int x, r, rN = 0, oN;
// rN - To store the reverse number
// oN - To store the original number
// r - To store the remainder
cout << "Enter an integer number::\n";
cin >> x;
oN = x;
// reverse number will be stored during iteration
while (x != 0) {
r = x % 10;
rN = rN * 10 + r;
x /= 10;
}
// if original number will match with reverse then palindrome case will be true
if (oN == rN) {
cout << "The " << oN << " is a palindrome number.";
} else {
cout << "The " << oN << " is not a palindrome number!";
}
return 0;
}
Output
Enter an integer number::
90009
The 90009 is a palindrome number.