Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help solving th following problem; and explain any steps taken . I will RATE your answer . Pascal's Triangle The French mathematician Blaise Pascal

Please help solving th following problem; and explain any steps taken . I will RATE your answer .

Pascal's Triangle

The French mathematician Blaise Pascal is credited with a triangular arrangement of binomial coefficients C(n,m). Sometimes read as "n choose m", this is the number combinations of n things taken m at a time. For example, there are C(52,5) = 2,598,960 distinct poker (5-card) hands.

There are n rows in the triangle, starting at n = 0, and each row has n+1 elements. There is only one way to choose n = 0 objects, so the first row is:

1

Each additional row has one more element from the previous row and is built by adding the two elements above it (or copying the single element at the ends). The second row is:

11

This means that given one object, there is one way to choose no objects and one way to choose one object. The next three rows make this clearer:

121 1331 14641

These are more conventionally printed as an isosceles triangle:

1 11 121 1331 14641

IV. Part1:pascal In this part, you will implement code to allow the user to submit a value and get the Pascal's

Triangle with the proper indentation.

Pascal's triangle cannot be easily computed with a single array. It needs two: an old one (oldRow[]) that holds the previous row and a new one (newRow[]) that gets the new one based on the old one. After printing out the new one, it's copied to the old one, ready for the next iteration.

2/5/2018 In a file pascal.c fill in the following template:

Lab 4 - Array

/* Programmer:

* Class: CptS 121, Spring 2018

* Programming lab: * Date:

* Description:

* This will work with any positive value of MAX_ROWS. This one

* produces cool-looking results on an 80-character width console, but

* you might want to set it to a lower value like 5 while debugging.

* (Or a higher value if you want to print a poster!)

*/ #include #define MAX_ROWS 16 int main(void) {

/* * * * * * * * * * * * * * * * 

declare int arrays oldRow[] and newRow[] to hold 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

for

m from 0 to n, inclusive if m is zero (first item on row)

set newRow[m] to 1 else if m is n (last item on row)

set newRow[m] to 1 else (middle items on row)

set newRow[m] to the sum of the m'th and the m-1'st elements of oldRow[]

m from 0 to n, inclusive print the m'th element of newRow[] (without a newline) set oldRow[m] to newRow[m] (for the next iteration)

print a newline 

*/ return 0; }

Compile the program with:

 $ cc -Wall pascal.c -o pascal 

Here's an example your compiled program should duplicate:

$ ./grade

1

1 1

1 2 1

1 3 3 1

1 4 6 4 1

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_2

Step: 3

blur-text-image_3

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

Database Design Application And Administration

Authors: Michael Mannino, Michael V. Mannino

2nd Edition

0072880678, 9780072880670

More Books

Students also viewed these Databases questions