what's wrong with this if function
Well, this seems to be a bit strange..
this is the simple palindrome code..
Code:
# include <stdio.h>
int palindrome (int n)
{
int rev=0, k;
while (n!=0)
{
k = n%10;
rev = rev * 10 + k;
n = n/10;
}
if (rev == n)
return n;
else
return 0;
}
int main (void)
{
int n=9009;
printf("%d",palindrome(n));
}
As we know the input N is palindrome.. but its returning 0..
I checked the value of rev after the calculation ... it went fine.
but when I use this condition
if (rev ==n)
something is going wrong inside..
I checked the value of rev & n values after that .. they get turning to 0;
why ?
where's the little bug, that's hiding?