To check whether the number is palindrome or not

Question:
Write a program to check whether the given number is palindrome or not.
Logic:
- Get the input number from the user.
- Then reverse the given number using any algorithm.
- And compare the given number with reversed number.
- Print the output as palindrome or not.
Algorithm:
- Get the input value from the user.
- Find the last digit of the number.
- Then reverse the number using some calculation.
- Removes the last digit by dividing the number with 10.
- Repeat step 2 to 4 until it ends.
- Then print the valid output.
Program:
[code lang=”c”]
#include<stdio.h>
#include<math.h>
void main()
{
int a,r,sum=0,b;
clrscr();
printf("enter the number:");
scanf("%d",&a);
b=a;
while(a>0) //reverse the number
{
r=a%10; //finds the last digit
sum=r+sum*10; //reversing number
a=a/10; //removes the last digit
}
if(b==sum) //compare the given number with reversed number
{
printf("Given number is palindrome:");
}
else
{
printf("Given number is not palindrome:");
}
getch();
}
[/code]
You might also like:
To print all palindromes in a word