A Program to Check a Palindrome Number
In this example, we are giving a program to check whether a number is palindrome or not. A number can be said palindrome if the reverse of the number is equal to the actual number.
Program to check palindrome:
#include <iostream>
using namespace std;
int main() {
int n, reverse_number = 0, remainder, actual_number;
cout << "Enter an integer: ";
cin >> n;
actual_number = n;
// reversed integer is stored in reverse_number
while (n != 0) {
remainder = n % 10;
reverse_number = reverse_number * 10 + remainder;
n /= 10;
}
// palindrome if actual_number and reverse_number are equal
if (actual_number == reverse_number)
cout << actual_number << " is a palindrome.";
else
cout << actual_number << " is not a palindrome.";
return 0;
}
Output:
Enter an integer: 3773 3773 is a palindrome.