codescracker


c++

C++ Program to Check Number is Palindrome or Not



« Previous Program Next Program »


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:

/* C++ Program - Check Palindrome or Not */
		
#include<iostream.h>
#include<conio.h>
void main()
{
	clrscr();
	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)  // check if original number is equal to its reverse
	{
		cout<<"Palindrome";
	}
	else
	{
		cout<<"Not Palindrome";
	}
	getch();
}

When the above C++ program is compile and executed, it will produce the following result. Above C++ Programming Example Output (palindrome):

C++ program check palindrome number

Above C++ Programming Example Output (not palindrome):

check palindrome number in c

Same Program in Other Language

You may like the same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test