Thursday, April 3, 2014

C++ Program to check whether the number is palindrome or not

C++ Program to check whether the number is palindrome or not
A palindrome is a word, phrase, number, or other sequence of symbols or elements, whose meaning may be interpreted the same way in either forward or reverse direction.[1] Famous examples include "Amore, Roma", "A man, a plan, a canal: Panama" and "No 'x' in 'Nixon'". --- wiki

#include<iostream.h>
#include<conio.h>
class palindrome
{
int n1,n2,rem,rev;
public:
void input()
{
cout<<"Enter the number\n";
cin>>n1;
}
void calculation()
{
rev=0;
n2=n1;
while (n1>0)
{
rem=n1%10;
n1=n1/10;
rev=rev*10+rem;
}
}
void output()
{
if(n2==rev)
cout<<"Number is palindrome";
else
cout<<"Number is not palindrome";
}
};
void main()
{
clrscr();
palindrome a;
a.input();
a.calculation();
a.output();
getch();
}

No comments:

Post a Comment