Question: Pascal's triangle ( see here and here ) is an interesting pattern of numbers named after the French mathematical Blaise Pascal. Your task is to

Pascal's triangle (see here and here) is an interesting pattern of numbers named after the French mathematical Blaise Pascal. Your task is to write a program to calculate and print out Pascal's triangle.
Your C source file for this task must be named task1.c and placed in the top-level directory of your git project for this coursework.
Details
Your program should calculate Pascal's triangle for a given number of rows specified by the user and print out the triangle in the format described below. There are many ways to calculate the triangle (see the links in the Overview above for a starting point).
You are free to choose whichever method you want to implement your program with the following restrictions:
you must calculate the values in the triangle, rather than e.g. store them in a precomputed lookup table
your implementation must contain a correctly declared main function
you are not allowed to use global variables
Your program should allow the user to specify the number of rows to print as a command line argument when your program is run. That is, if the user wants to print out the first 5 rows of Pascal's triangle, they will type:
$ ./task15
Your program should only allow users to specify integer values between 1 and 20 inclusive for the number of rows to print. If any other value for the number of rows is specified by the user (or no value at all), then your program should print an error message and return a non-zero exit value. If a valid value is specified, your program should print Pascal's triangle for the specified number of rows and return an exit value of zero (i.e. success).
Hint: Use argc and argv to get the number of rows specified by the user when the program is run. Use the standard library function strtol to convert the number of rows entered from a string to an integer and to check that the user has entered an integer. If you write your string to integer conversion code as a function, you can easily reuse it in Tasks 2 and 3 below.
Your program should output the rows of Pascal's triangle to stdout in reverse order. Here is an example output:
$ ./task15146411331121111
As in this example, you should output the numbers as a triangle.
One possible way of implementing this task is to write three functions (in addition to main). The first function takes the number of rows n input by the user as an argument and calculates and outputs the values in each row of the triangle using two nested loops. The outer loop iterates over the rows i.e. i =[n,0], and the inner loop iterates over the range j =[0, i]. In the inner loop, a second function which calculates C(i, j)(the possible combinations of i objects from a set of j objects) is called repeatedly. This second function uses the standard equation to calculate C(i, j), calling a third function several times to calculate the factorial of a given number i.e. this third function takes a number x as an argument and returns x!. Be careful with integer overflow, as calculating factorials of even small numbers will produce numbers which may be too big to store in an int type. Task 1
Overview
Pascal's triangle (see here and here) is an interesting pattern of numbers named after the French mathematical Blaise Pascal. Your task is to write a program to calculate and print out Pascal's triangle.
Your C source file for this task must be named task1.c and placed in the top-level directory of your git project for this coursework.
\({}^{2}\) Details
Your program should calculate Pascal's triangle for a given number of rows specified by the user and print out the triangle in the format described below. There are many ways to calculate the triangle (see the links in the Overview above for a starting point).
You are free to choose whichever method you want to implement your program with the following restrictions:
- you must calculate the values in the triangle, rather than e.g. store them in a precomputed lookup table
- your implementation must contain a correctly declared main function
- you are not allowed to use global variables
Your program should allow the user to specify the number of rows to print as a command line argument when your program is run. That is, if the user wants to print out the first 5 rows of Pascal's triangle, they will type: Your program should only allow users to specify integer values between 1 and 20 inclusive for the number of rows to print. If any other value for the number of rows is specified by the user (or no value at all), then your program should print an error message and return a non-zero exit value. If a valid value is specified, your program should print Pascal's triangle for the specified number of rows and return an exit value of zero (i.e. success).
Hint: Use argc and argv to get the number of rows specified by the user when the program is run. Use the standard library function strtol to convert the number of rows entered from a string to an integer and to check that the user has entered an integer. If you write your st
Pascal's triangle ( see here and here ) is an

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 Programming Questions!