codescracker


c

C Program to Check Original is Equal to its Reverse or Not



« Previous Program Next Program »


Check Original Equal Reverse or Not in C

To check whether the reverse of a number is equal to its original or not in C programming, you have to ask to the user to enter the number and reverse the number then check whether 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.

C Programming Code to Check Original is Equal to its 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 Reverse is Equal to its Original or Not */
		
#include<stdio.h>
#include<conio.h>
void main()
{
	clrscr();
	int num, orig, rev=0, rem;
	printf("Enter a number : ");
	scanf("%d",&num);
	orig=num;
	while(num>0)
	{
		rem=num%10;
		rev=rev*10+rem;
		num=num/10;
	}
	if(orig==rev)
	{
		printf("Reverse is equal to original");
	}
	else
	{
		printf("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 to check original is equal to its reverse or not

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

reverse original program c

Same Program in Other Programming Language

You may also like same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test