0
Program to check whether the given number is palindrome or not
3 Answers
+ 5
#include<iostream>
using namespace std;
int main(void)
{
int no, n, rev=0, dgt;
//initially, rev is zero.
cout<<"Enter a Number - ";cin>>no;
n=no;
//so that original no can be printed later.
while(n!=0)
{
dgt=n%10;
//to get last digit of n
rev=rev*10+dgt;
//to add digit to reverse and multilply by 10 to create new vacant space in rev
n/=10;
//since n is int all decimals will go away and next digit can be obtained.
}
cout<<"Number - "<<no<<endl;
cout<<"Reverse - "<<rev<<endl;
//now the check below.
if(no==rev)
cout<<"Palindrome";
else
cout<<"Not a Palindrome";
}
+ 4
That should do it...
0
#include<iostream>
using namespace std;
int main()
{
int num,n,r,rev;
rev = 0;
cout<<"Enter the number: ";
cin>>num;
n = num;
while(n>0)
{
r = n%10;
rev = (rev*10)+r;
n = n/10;
}
if(num==rev)
cout<<"Number "<<num<<" is palindrome";
else
cout<<"Number "<<num<<" is not palindrome";
}