ProgrammingModerateAccenture · Capgemini
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer m[4][4], s = 0
for (each i from 0 to 3)
for (each j from 0 to 3)
m[i][j] = 4 * i + j + 1
end for
end for
for (each i from 0 to 3)
for (each j from 0 to 3)
if (i == 0 OR j == 0 OR i == 3 OR j == 3)
s = s + m[i][j]
end if
end for
end for
Print s- A. 102
- B. 136
- C. 34
- D. 120
Correct answer: A. 102
m holds 1 to 16 row by row. The border leaves out only the inner 6, 7, 10, 11 (sum 34), so the border sum is 136 − 34 = 102.
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? Boolean comp[0..30] = all false Integer s = 0 for (each i from 2 to 30) if (not…
- What will be the output of the following pseudocode? Function isPrime(Integer n) if (n < 2) return false for (each d from 2 to n - 1) if…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Function phi(Integer n)…
- What will be the output of the following pseudocode? Integer s = 0 for (each i from 1 to 99) if (i mod 2 == 1) s = s + i else s = s - i…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer n = 100, steps = 0…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer dp[0..10] dp[1] = 0…