Pregunta de entrevista de Dolby

How do you reverse an integer value (e.g. 1234 => 4321)

Respuestas de entrevistas

Anónimo

30 abr 2012

I came up with a quicky but it has a problem, if the number ends with a "0", it wont print in the reversed number, will resort to some ugly hack thing for that. int reverseInt(int num) { int res = 0; do { res *= 10; res += (num % 10); num /= 10; } while (num > 0); return res; }

Anónimo

1 feb 2010

can be done with one loop, and modular arithmetic

1