ProgrammingVery hardWipro NLTH · Cognizant GenC
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer w[5][5], i, j
for (i = 0; i < 5; i = i + 1)
for (j = 0; j < 5; j = j + 1)
if (i == 2 AND j == 2)
w[i][j] = 0
else if (i == 0 AND j == 0)
w[i][j] = 1
else
w[i][j] = (i > 0 ? w[i-1][j] : 0) + (j > 0 ? w[i][j-1] : 0)
end if
end for
end for
Print w[4][4]- A. 70
- B. 36
- C. 40
- D. 34
Correct answer: D. 34
Without the block there are C(8,4) = 70 paths; the paths through (2,2) number 6 x 6 = 36, so 70 - 36 = 34.
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? String A = "AXYT", B = "AYZX" Integer L[5][5] = all 0, i, j for (i = 1; i <= 4; i = i…
- What will be the output of the following pseudocode? Integer n = 9, steps = 0 while (n != 1) if (n mod 2 == 0) n = n / 2 else n = 3 n + 1…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division.) Integer x, y Set x = 17, y =…
- What will be the output of the following pseudocode? Integer s = 0 for (each i from 1 to 10) if (i mod 2 == 0) s = s + i end if end for…
- What will be the output of the following pseudocode? Integer a = 6, b = 4 a = a + b b = a - b a = a - b Print a, b
- What will be the output of the following pseudocode? Integer n = 5, f = 1 while (n > 1) f = f n n = n - 1 end while Print f