Subj : Re: Reversing a number To : comp.programming From : Willem Date : Mon Sep 12 2005 09:15 am Rob wrote: ) Willem wrote: )> Roger wrote: )> ) "Irrwahn Grausewitz" wrote in message )> ) news:shv7i1p3on0qpsr2rumeifst69o8tjtp32@4ax.com... )> )> But why treat the first iteration as a special case? )> )> Just replace the two lines above with: )> )> )> )> int n = 0; )> )> )> )>> while (i) )> )>> { )> )>> n *= 10; )> )>> n += i % 10; )> )>> i /= 10; )> )>> } )> )>> return n; )> )>>} )> ) )> ) Then reverse(10000) is (1). )> )> Of course it is; the function returns an integer, after all. ) ) I think the OP means a number in the mathematical sense of the word. ) ie:- ) ) 1 -> 1 ) 21 -> 12 ) 5634 -> 4365 And what, pray tell, would be the reverse of 10000, as a number in the mathematical sense of the word ? ) 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. SaSW, Willem -- Disclaimer: I am in no way responsible for any of the statements made in the above text. For all I know I might be drugged or something.. No I'm not paranoid. You all think I'm paranoid, don't you ! #EOT .