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 taskc and placed in the toplevel 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 eg 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 rows of Pascal's triangle, they will type:
$ task
Your program should only allow users to specify integer values between and 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 nonzero 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 ie 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 and below.
Your program should output the rows of Pascal's triangle to stdout in reverse order. Here is an example output:
$ task
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 ie i n and the inner loop iterates over the range j i In the inner loop, a second function which calculates Ci jthe possible combinations of i objects from a set of j objects is called repeatedly. This second function uses the standard equation to calculate Ci j calling a third function several times to calculate the factorial of a given number ie 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
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 taskc and placed in the toplevel 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 eg 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 rows of Pascal's triangle, they will type: Your program should only allow users to specify integer values between and 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 nonzero 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 ie 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
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
