Question d’entretien chez NVIDIA

given 2 unsigned ints a and b, return 1 unsigned int = a/b, rounded to nearest int without float operation

Réponses aux questions d'entretien

Utilisateur anonyme

4 juil. 2013

the round up operation is not useful to find the"nearest int" you could use: ((a%b)>=(b-(a%b)))?(a/b)+1:(a/b)

4

Utilisateur anonyme

21 févr. 2015

return (int) ( ( a + (b>>1) ) / b ) ;

1

Utilisateur anonyme

28 janv. 2015

You can derive the answer: in order to round up, you want REMINDER >= b/2 let's play: 2*REMINDER >= b What is REMINDER??? 2*(a%b) >= b So, if TRUE: answer is (a%b)+1 if FALSE, the answer is a%b

Utilisateur anonyme

21 nov. 2012

return (a + b - 1) / b (round up operation)

1