Question
C++ code Implement a function called pascal that returns a dynamically allocated two-dimensional array that represents the rows of Pascal's triangle. That means the first
C++ code Implement a function called pascal that returns a dynamically allocated two-dimensional array that represents the rows of Pascal's triangle. That means the first row will have length 1 and contain a single 1. The second row will have length 2 and contain two 1's. The third row will have length 3 and contain the three values 1, 2, 1. In general, the row at index i will have length i+1 and values filled in as follows: The first and last elements in the row are equal to 1 and for each index j in the range {1, ..., i-1} the element at that index will be the sum of the elements at indexes j-1 and j from the previous row. See the picture below to see how that works.
The prototype for pascal is int ** pascal(int n); , n is the total number of rows, e.g. for the pic above n would be 8 since there are eight rows.
Use dynamic allocation except this time the rows will all have different lengths.
To test code with:
#includevoid printPascal(int ** array, int n) { for (int i = 0; i for (int j = 0; j cout for (int j = 0; j cout cout } }
Result of output of printPascal when passed an array obtained from a call to pascal(10) and second parameter 10 should look like this:
Please provide code for whole program and function itself.
111121133114641151010511615201561172135352171 1Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started