ProgrammingModerateTCS NQT · Wipro
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer m[3][3] = {{11, 2, 4}, {4, 5, 6}, {10, 8, -12}}
Integer d1 = 0, d2 = 0
for (each i from 0 to 2)
d1 = d1 + m[i][i]
d2 = d2 + m[i][2 - i]
end for
Print d1, d2, abs(d1 - d2)- A. 4 19 15
- B. 4 19 23
- C. 19 4 15
- D. 4 18 14
Correct answer: A. 4 19 15
Main diagonal: 11 + 5 − 12 = 4. Other diagonal: 4 + 5 + 10 = 19. Absolute difference 15: output 4 19 15.
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? (/ truncates toward zero and mod keeps the sign of the dividend (as in C)) Integer x…
- What will be the output of the following pseudocode? Boolean seen[0..6] = all false Integer c = 0 for (each i from 1 to 20) Integer r = (i…
- What will be the output of the following pseudocode? Function gcd(Integer a, Integer b) if (b == 0) return a return gcd(b, a mod b) End…
- What will be the output of the following pseudocode? String s = "hello world of code" Integer changes = 0 for (each i from 0 to length(s)…
- What will be the output of the following pseudocode? (strings are indexed from 0) String s = "ABCABCAB" Integer n = length(s), p = n for…
- What will be the output of the following pseudocode? (strings are indexed from 0; + joins strings) String s = "ABCDEF", r = "" Integer k =…