Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Manga Guide To Databases

Authors: Mana Takahashi, Shoko Azuma, Co Ltd Trend

1st Edition

1593271905, 978-1593271909

More Books

Students also viewed these Databases questions