GATE 2014 CS (CS2) – Question 21
n and p are unsigned int in C. To set p to n choose 3 for large n, which is most likely correct?
Practise this question in The GATE Grind →
Show answer and explanation
Correct answer: (B) p = n * (n-1) / 2 * (n-2) / 3;
Explanation
OptionB divides the always-even product n(n−1) by2 before the next multiplication, reducing intermediate magnitude without losing information. The remaining product with(n−2) is divisible by3. Thus **B** is most likely correct for large representable results. It still cannot guarantee correctness if an intermediate or final value exceeds the unsigned range.