ProgrammingVery hardProduct company OA
What will be the output of the following pseudocode? (/ is integer division.)
What will be the output of the following pseudocode? (/ is integer division.)
Integer c = 0
for (n = 1 to 50)
Integer d = 0
for (k = 1 to n)
if (n mod k == 0)
d = d + 1
end if
end for
if (d == 3)
c = c + 1
end if
end for
Print c- A. 7
- B. 15
- C. 4
- D. 3
Correct answer: C. 4
A number has exactly 3 divisors only if it is the square of a prime p (divisors 1, p, p²). Prime squares up to 50: 4, 9, 25, 49 → 4. '15' counts primes (2 divisors); '7' counts all perfect squares up to 49.
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? (&, |, ^ are bitwise AND, OR, XOR; << is a left shift.) Integer x = 0 for (i = 0 to…
- What will be the output of the following pseudocode? ('ref' parameters are passed by reference; others by value.) Procedure p(ref Integer…
- What will be the output of the following pseudocode? (/ is integer division.) Function A(Integer n) if (n <= 1) return n end if return B(n…
- What will be the output of the following pseudocode? (x is an 8-bit unsigned value; & is bitwise AND, | is OR, << and >> are shifts.)…
- What will be the output of the following pseudocode? (/ is integer division.) Integer x = 10 x = x + x 2 - 4 / 2 Print x
- What will be the output of the following pseudocode? for (i = 10; i >= 1; i = i - 3) Print i end for