codescracker


c++

C++ Program to Check Original Equal Reverse or Not



« Previous Program Next Program »


Check Original Equal Reverse or Not

To check that the original number is equal to its reverse or not in C++ programming, you have to ask to the user to enter the number and reverse that number then check that reverse is equal to original or not, before reversing the number make a variable of same type and place the value of the original number to that variable to check after reversing the number as shown here in the following program.

C++ Programming Code to Check Original Equal Reverse or Not

Following C++ program ask the user to enter a number, to find its reverse and then check whether reverse is equal to its original or not, then display the result on the screen:

/* C++ Program - Check Original Equal Reverse or Not */
		
#include<iostream.h>
#include<conio.h>
void main()
{
	clrscr();
	int num, orig, rev=0, rem;
	cout<<"Enter a number : ";
	cin>>num;
	orig=num;
	while(num>0)
	{
		rem=num%10;
		rev=rev*10+rem;
		num=num/10;
	}
	if(orig==rev)
	{
		cout<<"Reverse is equal to original";
	}
	else
	{
		cout<<"Reverse is not equal to original";
	}
	getch();
}

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

C++ program check reverse original

Above C++ Programming Example Output (for reverse not equal to original):

reverse original program 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