#include <iostream>
using namespace std;
int main()
{
int n, num, digit, rev = 0;
cout << "Enter a positive integer: ";
cin >> n;
num = n;
do {
digit = num % 10;
rev = (rev * 10) + digit;
num = num / 10;
} while (num != 0);
if (n == rev) {
cout << n << " is a palindrome number." << endl;
} else {
cout << n << " is not a palindrome number." << endl;
}
return 0;
}
Enter a positive integer: 12321
12321 is a palindrome number.
cout
. We then read the integer input using cin
. We store a copy of the integer in a variable called num
.do-while
loop to reverse the digits of the integer and store the result in a variable called rev
. Inside the loop, we first find the last digit of the integer using the modulo operator %
, and then add it to the reversed integer by multiplying the reversed integer by 10 and adding the last digit. We then remove the last digit from the integer by dividing it by 10.n
is equal to the reversed integer rev
. If they are equal, we print that n
is a palindrome number. Otherwise, we print that n
is not a palindrome number.