Subj : Re: Reversing a number To : comp.programming From : Irrwahn Grausewitz Date : Mon Sep 12 2005 01:45 pm Gerry Quinn wrote: >In article , willem@stack.nl >says... >> Rob wrote: >> )> )>> while (i) >> )> )>> { >> )> )>> n *= 10; >> )> )>> n += i % 10; >> )> )>> i /= 10; >> )> )>> } >> )> )>> return n; >> ) As Jerry Quinn pointed out it's simplest to convert it to a string then >> ) reverse it and convert it back again. >> >> That can only be simplest if 'convert to a string' is considered a simple >> operation. Otherwise the above piece of code is simpler. > >The above bit of code *is* effectively converting it to a string (in >base-10 representation, and with the characters 0-9 represented by >digits), Just to mention, that this definition of string is far from being compatible with the C standard. > albeit in piecemeal fashion. Oh, and multiplication by 10 is appending a 0 to a string?!? Have to remember that one... :> Best regards -- Irrwahn (irrwahn35@freenet.de) .