C++ program to check whether the number is palindrome or not. - coderforcoders

Search

Wednesday, 13 March 2019

C++ program to check whether the number is palindrome or not.

#include<iostream>
using namespace std;
class palindrom{
public:
int num,rev=0,rem,temp;
void checkPalindrom()
{
temp=num;
do
{
rem=temp%10;
rev=(rev*10)+rem;
temp=temp/10;
}
while(temp);
if(num==rev)
cout<<"It is a palindrome\n";
else
cout<<"It is not a palindrome\n";
}
};
int main()
{
palindrom obj1;
cout<<"Please enter a number\n";
cin>>obj1.num;
obj1.checkPalindrom();
cout<<endl;
}

Output 1:
Please enter a number
1234
It is not a palindrom

Output 2:
Please enter a number
101
It is a palindrom

Output 3:
Please enter a number
143
It is not a palindrom



No comments:

Post a Comment