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

0
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
#include
#include
void main()
{
long int n, num, rev = 0, dig;
clrscr();
printf(“nnt Enter a number:- “);
scanf(“%ld”, #);
n = num;
while(num>0)
{
dig = num % 10;
rev = rev * 10 + dig;
num = num / 10;
}
if (n == rev)
printf(“nt It is palindrome”);
else
printf(“nt It is not palindrome”);
getch();
}
Share.

About Author