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:

  1. A.

    ⌈log₂ n⌉ + 1

  2. B.

    n

  3. C.

    ⌈log₂ n⌉

  4. D.

    ⌊log₂ n⌋ + 2

Attempted by 475 students.

Sign up free to check your answer

Sign up free

Explore the full course: Zero To Hero

Loading lesson…