PALINDROME NUMBER
A number is called palindrome if it remains same after reversing its digits.
For example,
Reverse(2002) = 2002 i.e. Palindrome Number
Reverse(2111) = 1112 i.e. Not a Palindrome Number
STEPS
1. Input a number(num).
2. Initialize another variable(original) with num. It would be used to compare the reversed number.
3. Obtain the last digit of num.
4. Assign rev(Initially 0) with (rev*10) + lastnum.
5. Decrement num as num/10.
6. Repeat steps 3-5 until num>0.
7. Compare Reversed Number(rev) with Original Number(original). If they are same, the given number is palindrome else not.
PROGRAM
//Program to check whether a number is palindrome or not
#include<iostream>
using namespace std;
int main()
{
int num, rev=0, original, lastnum;
cout<<"ENTER A NUMBER: ";
cin>>num;
original=num;
while(num>0)
{
lastnum=num%10;
rev=(rev*10) + lastnum;
num=num/10;
}
if(original==rev)
{
cout<<"GIVEN NUMBER "<<original<<" IS A PALINDROME";
}
else
{
cout<<"GIVEN NUMBER "<<original<<" IS NOT A PALINDROME";
}
return 0;
}
OUTPUT