...
Question 2317 – KVS DEC-2017
May 9, 2024
Question 14644 – DSSSB PGT 2018 Male
May 9, 2024
Question 2317 – KVS DEC-2017
May 9, 2024
Question 14644 – DSSSB PGT 2018 Male
May 9, 2024

Question 8627 – Programming

Suppose n and p are unsigned int variables in a C program. We wish to set p to nC3. If n is large, which one of the following statements is most likely to set p  correctly?

Correct Answer: B

Question 39 Explanation: 
n & p are unsigned int variable.
From the options n*(n-1)*(n-2) will go out of range. So eliminate A & D.
n*(n-1) is always an even number. So subexpression n(n-1)/2 also an even number.
n*(n-1)/ 2*(n-2), gives a number which is a multiple of 3. So dividing with 3 will not have any loss. Hence B is option.
A
p = n * (n-1) * (n-2) / 6;
B
p = n * (n-1) / 2 * (n-2) / 3;
C
p = n * (n-1) / 3 * (n-2) / 2;
D
p = n * (n-1) * (n-2) / 6.0;
0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
error: Alert: Content selection is disabled!!