what is the math formula(algorithm) for flipping any number like:
47->74
1655 -> 5561
12345->54321
1190 -> 911
??
Printable View
what is the math formula(algorithm) for flipping any number like:
47->74
1655 -> 5561
12345->54321
1190 -> 911
??
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.
If you want an actual number that you can use, you could use something like this:
If all you want to do is reverse the data, you could do as itCbitC suggested, or, if you have a string representation of the number, you could just print the string in reverse. :)Code:newnum = 0
for each digit in number:
digit = number % 10
newnum = newnum * 10 + digit
solved it thanks :)