Question: I need to write a recursive program that takes as input a non-negative integer n and prints out the first n + 1 rows of

I need to write a recursive program that takes as input a non-negative integer n and prints out the first n + 1 rows of Pascals triangle.

The program has to be decomposed into functions. The triangle should be printed as a right angle triangle.

Example: On input n = 0, the program may output:

Number n: 0

1

and on input

n = 7, your program may output:

1

1 1

1 2 1

1 3 3 1

1 4 6 4 1

1 5 10 10 5 1

1 6 15 20 15 6 1

1 7 21 35 35 21 7 1

The values for row I can be obtained from row I 1 as follows:

The first and last entries are 1

The entry at position j (apart from the first and last entries) in row i is the sum of the entries at position j 1 and j in the previous row.

The program also has to use a function printPascal.

Input: List L containing the previous line in Pascals triangle or the empty list if there is no previous line.

n, the number of lines that still need to be printed in the triangle (excluding the line printed by this call of the function).

Output: Updates list L to contain the next line in Pascals triangle and prints this line.

This should be in python programme format

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!