2016-12-13 17:18:53 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
int n, reversedInteger = 0, remainder, originalInteger;
|
|
|
|
|
|
|
|
printf("Enter an integer: ");
|
|
|
|
scanf("%d", &n);
|
|
|
|
|
|
|
|
originalInteger = n;
|
|
|
|
|
2020-05-30 04:23:24 +08:00
|
|
|
// reversed integer is stored in variable
|
|
|
|
while (n != 0)
|
2016-12-13 17:18:53 +08:00
|
|
|
{
|
2020-05-30 04:23:24 +08:00
|
|
|
remainder = n % 10;
|
|
|
|
reversedInteger = reversedInteger * 10 + remainder;
|
2016-12-13 17:18:53 +08:00
|
|
|
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);
|
2020-05-30 04:23:24 +08:00
|
|
|
|
2016-12-13 17:18:53 +08:00
|
|
|
return 0;
|
|
|
|
}
|