Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Blaise Pascal was a French mathematician and philosopher who lived in the mid-1600's. He accomplished much in his lifetime, including the construction of a mechanical

Blaise Pascal was a French mathematician and philosopher who lived in the mid-1600's. He accomplished much in his lifetime, including the construction of a mechanical calculator and some very early work in combinatorics and the development of differential calculus. In his studies, he devised what has become known as Pascal's Triangle, http://ptri1.tripod.com/ which simplifies the calculation of the coefficients of the expression (x + y)n, where n is a positive integer. That is, we all know

(x + y)2 = x2 + 2xy + y2

(implying coefficients of 1,2,1), but what are the coefficients of (x + y)3 or (x + y)4 or (x + y)10 By using Pascal's Triangle, these values can be quickly calculated.

The first part of Pascal's Triangle looks like this: 1 11 12 1

133 1 1464 1

From examination, you can see that if we number the rows beginning at 0, the values listed on each line correspond to the coefficients where n is equal to the line number. You can also see, except for the 1's, any coefficient is found simply by adding together the 2 numbers diagonally above it. (And, if you think about it, picture 0's everywhere along the outside edge, and the 1's can be calculated the same way!)

Write a lab6.c that calculates and displays the first k rows of Pascal's Triangle. Where k is a value entered by the user. (For example: n = 16 it contains the coefficients for n=15 in the last row.) It must be displayed in the format shown above (not symmetrically)

As always I have provided: o an unchangeable main

o an unchangeable lab6.h

You cant use any statically sized arrays anywhere for this lab

METHODS TO WRITE int menu(); -- prompts the user with menu choices - must ensure the value entered is between 1 and 4 inclusive int readTotal(); -- prompts the user for a number - must ensure the value entered is greater than or equal to 0 int ** createTriangle(int n); -- creates and fills the appropriate pascals triangle and returns it int retrieveTotal(char * argv); -- takes the string from the command line as the first passed parameter and

converts it to a number. The number must be greater than or equal to 0. If not

prompt the user void cleanUp(int ** pascal, int n); -- cleans up each row first, and the the row of int * second;

void printTriangle(FILE * fout, int ** pascal, int n); - prints pascals triangle for n to the screen FILE * openOutputFileArgs(char * fn); - receives the filename from the command line and opens it for output

TO TURN IN A zip file containing Lab6 folder which will contain

cscd240Lab6.c

lab6.h

lab6.c

utils

o fileUtils.c

o fileUtils.h

cscd240Lab6out.txt output file with all runs

cscd240Lab6val.txt valgrind run

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

More Books

Students also viewed these Databases questions

Question

5-4 What are the current computer software platforms and trends?

Answered: 1 week ago

Question

How can you defend against SQL injection attacks?

Answered: 1 week ago

Question

7. Where Do We Begin?

Answered: 1 week ago