Check Number is Palindrome or Not C++

Check Palindrome or Not in C++

To check for palindrome i.e., whether entered number is palindrome or not in C++ programming,

you have to first ask from the user to enter a number.

Now to check whether the entered number is a palindrome number (if reverse of the number is equal to its original) or not a palindrome number

(if reverse of the number is not equal to its original), you have to first reverse the number and check whether reverse is equal to original or not.

If it is equal then the number is palindrome, otherwise not palindrome number as shown here in the following program.

C++ Programming Code to Check Palindrome or Not

Following C++ program ask to the user to enter a number to reverse it, then check whether reverse is equal to its original or not,

if it is equal then it will be palindrome else it will be not be palindrome:

#include <iostream>

using namespace std;

int main()
{

//
int num, rem, orig, rev=0;
cout<<"enter a number: ";
cin>>num;

//
orig=num;
while(num!=0)
{

//
rem=num%10;
rev=rev*10+rem;
num=num/10;
}

//
if(rev==orig)
{
cout<<"Palindrome";
}

//
else
{
cout<<"Not Palindrome";

}
return 0;



}

Xfer from : https://codescracker.com/cpp/program/cpp-program-palindrome-number.htm

posted @ 2019-05-23 08:45  Poission  阅读(168)  评论(0编辑  收藏  举报