Question: Please help writing the following C program, and explain any steps taken. I will RATE your answer . Write a function called pascal2D that returns

Please help writing the following C program, and explain any steps taken. I will RATE your answer .

Write a function called pascal2D that returns the sum of all elements in a 2-dimensional array

that contain the element for the pascals triangle

Create this program in a file pascal2D.c using this template:

/* Programmer:

* Class: CptS 121, Spring 2018

* Programming lab:

* Date:

* Description:

*/

#include

#define MAX_ROWS 16

int main(void)

{

/*

* declare int arrays pascal[][] hold MAX_ROWS+1 X MAX_ROWS+1 elements

* for n from 0 to MAX_ROWS-1 (thus looping MAX_ROWS times)

* compute and output appropriate indentation (see text below)

* for m from 0 to n, inclusive

* if m is zero (first item on row)

* set pascal[n][m] to 1

* else if m is n (last item on row)

* set pascal[n] [m] to 1

* else (middle items on row)

* set pascal[n][m] to the sum of the m'th and the m-1'st

* elements of pascal[n-1][] row

* for n from 0 to MAX_ROWS-1

* for m from 0 to MAX_ROWS-1, inclusive

* accumulate the element pascal[n][m]

* print a sum

*/

return 0;

}

Compile the program with:

$ cc -Wall pascal2D.c -o pascal2D

Here's a typical run:

The sum is : ??

Questions:

Why do oldRow[] and newRow[] have MAX_ROWS+1 rather

than MAX_ROWS elements?

How could you write the program with a MAX_ROWS as an input from the user?

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!