int reverseNumber(int n)
{
{
int a = 1;
int b = 1;
int y = 1;
int x = 0;
while(b != 0)
{
a = n % 10;
x = x * 10 + a;
b = n / 10;
n = b;
}
return x;
}
}
I hate this function. I finally got it to work with any number ex-321 yeilds 123. But when it starts with a 0, as in 012, it returns 1 & 0123 returns 38. (This is a case that my function must pass. It should just drop the 0.... 0123 --> 321 & 012 --> 12)
Can anyone save me with a suggestion or point to me where the error is.
If you hard coded these numbers in your source file, I think your results are correct. The reason is leading 0, it means the number is octal number, not decimal number. So octal 012 is decimal 10, octal 0123 is decimal 83......