CPP Program For Palindrome Number

A Palindrome number is that type of number when we reverse the number it remains the same.  eg: 12321

A user is asked to enter a number then we will reverse the number. If the reverse number is the same as the original number then it is a palindrome number

#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();
long a,n,rev=0,x;
cout << "enter the number" << endl;
cin >>n;

x=n;
while(n>0)
{
a=n%10;
rev=rev*10+a;
n=n/10;
}
cout << rev << endl;

if(rev==x)
{
cout << "Palindrome number" << endl;
}
else
{
cout << "Not Palindrome" << endl;
}
getch();
}

Output:
enter the number
12321  //entering the number  
12321  //first printing the reverse 
Palindrome number

 

Leave a Reply