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
- A. 15
- B. 14
- C. 100
- 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.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- The procedure below finds the smallest 0-based index i at which the prefix sum of [4, -1, 3, -2, 5] reaches at least 7. It prints i. What…
- Two sorted arrays a = [1, 4, 7] and b = [2, 3, 8, 9] are merged by the two-pointer procedure below, and the procedure prints the 4th…
- The procedure below repeatedly replaces x by the sum of its decimal digits, starting from x = 2^15, until x is a single digit, and prints…
- An array holds the values [3, 0, 2, 0, 1] (positions 0 to 4). The procedure below computes the water trapped above each position as…
- The Fibonacci sequence 1, 1, 2, 3, 5, ... is generated by the loop below, and the procedure prints how many terms are less than or equal…
- The string "aabcccdddd" is compressed by the procedure below, which replaces each run of equal letters by the letter followed by the run…