Recursion · 17 / 18 Exercise Medium

Pascal's triangle

Objective

In Pascal's triangle each row starts and ends with 1, and each middle number is the sum of the two above it in the previous row. It is a recursion: each row is computed from the previous one.

Instructions

  • Define pascal_row(k): row 0 is [1]; row k is computed from pascal_row(k - 1).
  • Read n (the number of rows) and show rows 0 to n - 1, with the numbers of each one separated by a space.
Input
5
Output
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise