Write A Program check whether a given number is palindrome or not in C Language

Write a Program in C to check whether a given number is palindrome or not.
The simplest method is to reverse the digits of the original number and check to see if the reversed number is equal to the original. This is not an efficient way of doing it but, for ints or long ints, it works well enough
What is the Logic :  The program expects the user to enter the number to check if palindrome. The entered number is reversed and stored in another variable. Finally the reversed number is checked for equality with the entered number. If they are the same, then it is a palindrome.
Example:-555,1221,1333331 are palindrome
//Program to check whether a number is palindrome or not
void main()
long int n, num, rev = 0, dig;
printf(“nnt Enter a number:- “);
scanf(“%ld”, #);
n = num;
dig = num % 10;
rev = rev * 10 + dig;
num = num / 10;
if (n == rev)
printf(“nt It is palindrome”);
printf(“nt It is not palindrome”);

About Author

I am Vivek Kumar living in India. I am in blogging almost 4 years. I love to share my knowledge gained from internet through my blogs. I like to experiment with different things and want to test every single thing. most of my experimental tests are success, If it fails I learn something and try to not to do that again.

Comments are closed.