ProgrammingModerateSSC CGL Tier 2 · IBPS PO Mains

The procedure below computes the integer square root of 200 by testing r = 0, 1, 2, ... and stopping at the largest r with (r + 1) (r + 1) <= 200. What is printed?

The procedure below computes the integer square root of 200 by testing r = 0, 1, 2, ... and stopping at the largest r with (r + 1) * (r + 1) <= 200. What is printed?
r = 0
while (r+1)*(r+1) <= 200: r = r + 1
Print r
  1. A. 15
  2. B. 14
  3. C. 100
  4. D. 16

Correct answer: B. 14

14 squared is 196 and 15 squared is 225, so the integer square root is 14. Testing r * r instead overshoots to 15, halving 200 gives 100, and stepping by 4 jumps to 16.

More Pseudocode and Code Tracing questions

Exams that ask this topic