Home C Programming Episode 12: Checking Palindrome Number

Episode 12: Checking Palindrome Number

0
SHARE

Explanation: What is a palindrome? Palindrome means a number is same even when it is reversed. Just for example 121. It remains same even if we reverse it.

So first is to reverse the number and then compare both the number whether it is same or not. Reversing number I told you in previous episode Link 

code:

#include <stdio.h>
#include <conio.h>

void main()
{
int n,rev=0,orginal;

printf(“Enter the Number: “);
scanf(“%d”,&n);
orginal=n;
while(n>0)
{
rev = (rev*10)+(n%10);
n=n/10;
}

if(orginal==rev)
{
printf(“\nNumber is palindrome”);
}
else
{
printf(“\nNumber is not palindrome”);
}

getch();
}

Output:

Enter the Number: 1234

Number is not palindrome

Enter the Number: 121

Number is palindrome

LEAVE A REPLY

Please enter your comment!
Please enter your name here