what is the math formula(algorithm) for flipping any number like:

47->74

1655 -> 5561

12345->54321

1190 -> 911

??

Printable View

- 12-08-2008transgalactic2flipping number question..
what is the math formula(algorithm) for flipping any number like:

47->74

1655 -> 5561

12345->54321

1190 -> 911

?? - 12-08-2008itCbitC
Use a for loop and divide the number by 10 in each iteration till it's zero while accruing the remainder, which is printed out after the loop is finished. Just my 2c and others may have better ways.

- 12-08-2008MK27
- 12-08-2008dwks
If you want an actual number that you can use, you could use something like this:

Code:`newnum = 0`

for each digit in number:

digit = number % 10

newnum = newnum * 10 + digit

- 12-09-2008transgalactic2
solved it thanks :)