Consider the following segment of C-code: int j, n; j = 1; while (j <= n) j =…
PYQ GATE 2007Modified — slightly modified from the official paper; see the solution
Consider the following segment of C-code: int j, n; j = 1; while (j <= n) j = j*2; The number of comparisons made in the execution of the loop for any n > 0 is:
- A.
⌈log₂ n⌉ + 1
- B.
n
- C.
⌈log₂ n⌉
- D.
⌊log₂ n⌋ + 2
Attempted by 475 students.
Sign up free to check your answer
Sign up freeLoading lesson…

