Subj : Re: Reversing a number To : comp.programming From : Irrwahn Grausewitz Date : Sun Sep 11 2005 01:11 pm zeroxia@gmail.com wrote: >Is this implementation not compiler-specific? >(For example, the case of which i is negative. That's not a problem, if you don't mind that the result will be negative, too. >int reverse(int i) >{ > int n = (i % 10); > i /= 10; 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; >} Best regards -- Irrwahn (irrwahn35@freenet.de) .