what is the math formula(algorithm) for flipping any number like:
47->74
1655 -> 5561
12345->54321
1190 -> 911
??
what is the math formula(algorithm) for flipping any number like:
47->74
1655 -> 5561
12345->54321
1190 -> 911
??
Last edited by transgalactic2; 12-08-2008 at 03:48 PM.
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.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
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
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
solved it thanks
Last edited by transgalactic2; 12-09-2008 at 09:22 AM.