ProgrammingModerateTCS NQT · Infosys
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer pas[0..6][0..6] = all 0
for (each i from 0 to 6)
pas[i][0] = 1
for (each j from 1 to i)
pas[i][j] = pas[i - 1][j - 1] + pas[i - 1][j]
end for
end for
Integer s = 0
for (each j from 0 to 6)
s = s + pas[6][j]
end for
Print pas[5][2], s- A. 10 64
- B. 10 32
- C. 15 64
- D. 5 64
Correct answer: A. 10 64
pas is Pascal's triangle: pas[5][2] = C(5, 2) = 10, and row 6 adds up to 2⁶ = 64. Output 10 64.
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? (All variables are integers, so / is integer division) Integer a[8] = {4, 9, 1, 7, 3…
- What will be the output of the following pseudocode? Integer c = 0 for (each a from 1 to 20) for (each b from a to 20) for (each h from b…
- What will be the output of the following pseudocode? String s = "Tcs NQT 2024 Exam!" Integer v = 0, c = 0, d = 0, o = 0 for (each ch in s)…
- What will be the output of the following pseudocode? String s = "AAAAA", r = "" Integer i = 0 while (i < length(s)) if (i + 1 < length(s)…
- What will be the output of the following pseudocode? (code(c) gives the ASCII code: 'A' = 65, 'a' = 97, '0' = 48; ^ is XOR) Integer x =…
- What will be the output of the following pseudocode? (| is OR, & is AND, << and >> are shifts) String s = "THE QUICK BROWN FOX" Integer…