Palindrome is a number that is same while it is reversed. So the logic behind palindrome is to reverse the given number and then check if the reversed number and the given number is same or not.
#include <stdio.h>
int main()
{
int x, y, i = 0,a;
printf("Enter an integer \n");
scanf("%d", &x);
a=x;
while (x > 0)
{
y = x % 10;
i = i * 10 + y;
x /= 10;
}
if (a == i)
printf("The number is a palindrome \n");
else
printf("The number is not a palindrome \n");
}
Source Code:
int main()
{
int x, y, i = 0,a;
printf("Enter an integer \n");
scanf("%d", &x);
a=x;
while (x > 0)
{
y = x % 10;
i = i * 10 + y;
x /= 10;
}
if (a == i)
printf("The number is a palindrome \n");
else
printf("The number is not a palindrome \n");
}
0 comments:
Post a Comment