Answered You can hire a professional tutor to get the answer.

QUESTION

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

I need to write recursive program that takes as input a non-negative integer n and prints out the first n + 1 rows of Pascal's 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 Pascal's 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 Pascal's triangle and prints this line.

This should be in python programme format

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question