Pergunta de entrevista da empresa Dolby

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

Respostas da entrevista

Sigiloso

30 de abr. de 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; }

Sigiloso

1 de fev. de 2010

can be done with one loop, and modular arithmetic

1