write a program to check the number is palindrome or not



We know that palindrome number means if we reverse the number then it will same as entered as input. The code for this program is as follows:

#include<iostream.h>
#include<conio.h>
void main()
{
int n,rev=0,temp;
clrscr();
cout <<"Enter Integer Number=";
cin>>n;
temp=n;
while(n>0)
{
rev=rev*10+n%10;
n/=10;
}
if(temp==rev)
{
cout <<"Number is palindrome="<<rev;
}
else
{
cout <<"Number is not palindrome="<<rev;
}
getch();
}

#include<iostream.h> used for input/output of data
#include<conio.h> provides several functions like clrscr(), getch() etc.
After that in main() function we have declared a variables n, rev=0, temp; after that we have used clrscr(); function to clear the scree when program will run. It will clear the previous output from any program. Now we have used the cout function that shows message “Enter Integer Number=”; and when we enter any number then this number is read by cin function and assign to n variable.
Here we have assigned the value of n to the temp variable. Here we have used a while loop. Here we have used the condition n>0 means loop will be continued while the value of n variable is greater than 0. Inside the loop, first of all we have to calculate the remainder of the n; when we use n%10 ; this will give the last digit of the number. After that we have used the rev*10+n%10; here we add the value of remainder with rev*10 and assign to rev. now we have to get the next digit so that we have used the n/10 and assign it to n. after that we have to check that the reversed number is equal to the original number. If reverse number is same as entered number then if part will be executed otherwise else block will be executed.
The output is as follows:

c++ program