eg.
10201 is a palindrome
10210 is not a palindrome
void main()
{
int num, rev=0;
cout<< "\n Enter a number :";
cin>> num;
/* truncate each digit from number and store the reverse of the number in rev */
int digit;
for(int i = num; i >0 ; i = i/10)
{
digit = i % 10; // get the last digit
rev = rev* 10 + digit;
}
if( rev == num )
cout<< "\n The " << num << " is a Palindrome. ";
else
cout << " \n The " << num << " is not a Palindrome. ";
getch();
}
10201 is a palindrome
10210 is not a palindrome
#include <iostream.h>
#include <conio.h>
void main()
{
int num, rev=0;
cout<< "\n Enter a number :";
cin>> num;
/* truncate each digit from number and store the reverse of the number in rev */
int digit;
for(int i = num; i >0 ; i = i/10)
{
digit = i % 10; // get the last digit
rev = rev* 10 + digit;
}
if( rev == num )
cout<< "\n The " << num << " is a Palindrome. ";
else
cout << " \n The " << num << " is not a Palindrome. ";
getch();
}