ProgrammingModerateAccenture · Cognizant pattern
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer c = 0, j
for (each i from 1 to 10)
j = i
while (j <= 10)
c = c + 1
j = j + i
end while
end for
Print c- A. 55
- B. 25
- C. 10
- D. 27
Correct answer: D. 27
For each i, j runs over i, 2i, 3i, ... up to 10, which is floor(10/i) values. Sum: 10 + 5 + 3 + 2 + 2 + 1 + 1 + 1 + 1 + 1 = 27. (This is also the total number of divisors of 1 to 10.)
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? (& is bitwise AND, | is bitwise OR, ^ is bitwise XOR, << and >> are left and right…
- What will be the output of the following pseudocode? (& is bitwise AND, | is bitwise OR, ^ is bitwise XOR, << and >> are left and right…
- How many numbers are printed when fun(5) is called? Function fun(Integer n) if (n <= 0) return end if fun(n - 1) Print n fun(n - 2) End…
- What will be the output? (A static variable keeps its value between calls and is initialised only once. The two calls in Print are…
- What will be the output of the following pseudocode? Integer a = 1, b = 2, c = 3 a = b + c b = a - b c c = a b - c Print a + b + c
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division.) Integer s = 0 for (each i…