|
From: Bolek V. <vr...@pa...> - 2001-04-19 14:09:47
|
> > How do I do if I want to use a number backwards?
> > For example: If I give the variable 'n' the number 12345
> > and want to use it as 54321.
>
> WHY?
> Though you can convert int to string with itoa and use the strrev to invert
> order of character and convert string to int with atoi.
My function is much more effective than the above way. It doesn't need
auxiliary arrays and works in a very straightforward way. The only thing
you must take care of is that if you want to use it for signed numbers
then:
a) I am not sure about behaviour of the % operator for negative numbers.
b) abs(minimum int, long, ...) might be > maximum int, long, ... => you
cannot simply check the sign and convert -number
Moreover - itoa is not a part of C/C++ standard.
--
============================================================
Ing. Boleslav Vrany
Stanice techniku DDM hl. m. Prahy
Pod Juliskou 2a
Praha 6 - Dejvice
16000
Czech Republic
tel. (420 2) 243 10 240
|