A smart way to invert a number
/This is my homework today to judge a number whether it's a palindrome./
/Most of us use array to solve the problem, but I find a way do not need an array./
include <stdio.h>
int main(int argc, const char * argv[])
{
int x,m,n=0;
printf("Enter a number:");
scanf("%d",&x);
for(int i=1;i<=x;i * =10)
{
m=x%(i * 10)/i;
n=m+n*10;
}
if (n==x)
{
printf("%d is a palindrome\n",x);
}
else
{
printf("%d is not a palindrome\n",x);
}
return 0;
}
浙公网安备 33010602011771号