Check Whether a Number is Palindrome or Not in C Program

Reversing in C
#include <stdio.h>
int main()
{
int n, reversedNumber = 0, remainder;
printf("Enter an integer: ");
scanf("%d", &n);
while(n != 0)
{
remainder = n%10;
reversedNumber = reversedNumber*10 + remainder;
n /= 10;
}
printf("Reversed Number = %d", reversedNumber);
return 0;
}


Palindrome in C
#include <stdio.h>
int main()
{
int n, reversedInteger = 0, remainder, originalInteger;
printf("Enter an integer: ");
scanf("%d", &n);
originalInteger = n;
// reversed integer is stored in variable
while( n!=0 )
{
remainder = n%10;
reversedInteger = reversedInteger*10 + remainder;
n /= 10;
}
// palindrome if orignalInteger and reversedInteger are equal
if (originalInteger == reversedInteger)
printf("%d is a palindrome.", originalInteger);
else
printf("%d is not a palindrome.", originalInteger);
return 0;
}


/*Palindrome or Not*/
#include<stdio.h>
int n,r,sum=0,temp;
main()
{
printf("Enter any number");
scanf("%d",&n);
temp=n;
while(n>0)
{
r=n%10;
sum=sum*10+r;
n=n/10;
}
n=temp;
if(n==sum)
printf("Palindrome");
else
printf("Not Palindrome");
}


 

Other Related Topic

ARMSTRONG NUMBER IN C PROGRAM (CLICK HERE)

Positive Negative or Zero (Click Here)