ProgrammingHardTCS NQT · Infosys
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer c = 0
for (each i from 1 to 10)
for (each j from 1 to i)
if (j * j > i)
break
end if
c = c + 1
end for
end for
Print c- A. 55
- B. 22
- C. 19
- D. 10
Correct answer: C. 19
For each i the inner loop counts j with j² ≤ i, i.e. ⌊√i⌋: 1, 1, 1, 2, 2, 2, 2, 2, 3, 3 for i = 1 to 10. Total 19.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- What will be the output of the following pseudocode? Integer m[3][3] = {{5, 1, 7}, {2, 9, 3}, {8, 4, 6}} Integer c = 0 Boolean peak for…
- What will be the output of the following pseudocode? String s = "CODE IS FUN", r = "", w = "" for (each i from 0 to length(s) - 1) if…
- What will be the output of the following pseudocode? (substring(t, i, k) is the k characters starting at index i; indices start at 0)…
- What will be the output of the following pseudocode? (& is AND, ^ is XOR, << is left shift) Integer a = 13, b = 11, carry, rounds = 0…
- What will be the output of the following pseudocode? ((b & 1) is evaluated before == ; & is AND, << and >> are shifts) Integer a = 13, b =…
- What will be the output of the following pseudocode? (^ is XOR, >> is right shift) Integer s = 0, g for (each i from 0 to 7) g = i ^ (i >>…