ProgrammingHardTCS NQT Advanced · Infosys SP
What will be the output of the following pseudocode? (All variables are integers, so / is integer division)
What will be the output of the following pseudocode? (All variables are integers, so / is integer division)
Boolean prime[2..50] // prime[i] is true exactly when i is prime
Integer c = 0
for (each n from 2 to 50)
for (each p from 2 to n - 1)
if (prime[p] AND n mod p == 0 AND prime[n / p] AND p < n / p)
c = c + 1
end if
end for
end for
Print c- A. 15
- B. 13
- C. 17
- D. 10
Correct answer: B. 13
Each n = p × q with primes p < q is counted once. Up to 50: 6, 10, 14, 22, 26, 34, 38, 46 (with 2), 15, 21, 33, 39 (with 3), 35 (5 × 7): 13 numbers. Squares like 4, 9, 25, 49 are excluded by p < n / p.
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 count = 0, n = 2, s = 0 while (count < 10) Boolean pr = true for (each d from…
- What will be the output of the following pseudocode? (XOR is true when exactly one side is true; NOT binds tighter than AND, which binds…
- What will be the output of the following pseudocode? Integer a[6] = {3, 8, 1, 9, 4, 7} Integer best = -1, i = 0, j = 5 while (i < j) best…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer n = 37, ones = 0…
- What will be the output of the following pseudocode? Integer a[5] = {2, 4, 1, 3, 5}, c = 0 for (each i from 0 to 3) for (each j from i + 1…
- Activities are given as (start, finish): (1,4) (3,5) (0,6) (5,7) (3,9) (5,9) (6,10) (8,11) (8,12) (2,14) (12,16). The procedure below runs…