Question d’entretien chez Dolby

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

Réponses aux questions d'entretien

Utilisateur anonyme

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

Utilisateur anonyme

1 févr. 2010

can be done with one loop, and modular arithmetic

1