hello, Im trying to code a loop that would take in a number then divide that number to 10. After that, I create an inverse of that number to see if it match and every time the number being divided by 10, i++. It seems that the inverse never forms fully before it gets checked. Any help on this?
and then check if 1234 == 4321 (it doesn't in this example) ?
num = x;
rev = 0;
while (num != 0) //this is pretty much what you have, I think, a little tighter.
{
rev *= 10;
rev += num%10;
num /= 10;
}
if (rev == x) //move this outside the loop?
...
Im trying something similar.
for example, 1234 becomes 123 then inverses of that which is 321 then check to see if they are the same if not continuing to cut down the right hand most digit then check again until they are the same. Also, seeing how many time it needed to cut down the last digit for it to be the same.