Palindrome Number in C++

Here you will get a C++ program to check whether a number is a palindrome or not.

A number is a palindrome if it is equal to its reverse. For example, 121 is a palindrome because if we reverse the order of digits then the number so obtained is equal to the original number.

#include<iostream>

using namespace std;

int main()
{
	unsigned long n,num,d,rev=0;
	cout<<"Enter any number: ";
	cin>>n;
	num=n;

	do
	{
		d=n%10;
		rev=(rev*10)+d;
		n=n/10;
	}while(n!=0);
	
	if(num==rev)
		cout<<endl<<"Number is Palindrome";
	else
		cout<<endl<<"Number is not Palindrome";

	return 0;
}

Output:

Enter a number: 12321
Number is Palindrome

3 thoughts on “Palindrome Number in C++”

Leave a Comment

Your email address will not be published. Required fields are marked *