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
  1. A. 10 64
  2. B. 10 32
  3. C. 15 64
  4. 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.

More Pseudocode and Code Tracing questions

Exams that ask this topic