Subj : Re: Reversing a number To : comp.programming From : Rob Thorpe Date : Sun Sep 11 2005 05:09 pm 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 As Jerry Quinn pointed out it's simplest to convert it to a string then reverse it and convert it back again. .