Implement a C function, named triangle, that outputs Pascal’s triangle. In general, the Pascal’s triangle can be represented as: 0C0 1C1 1C0 2C2 2C1 2C0 3C3 3C2 3C1 3C0 4C4 4C3 4C2 4C1 4C0 . . . where nCr represents how many ways there are to choose r from n, not counting duplicates. The formula used to calculate nCr can be written as: nCr = n!/r!(n −r)! where n! is the factorial of n. The function triangle: • is called by value where exactly one parameter (the number of rows of Pascal’s triangle) is passed to it. • returns void (i.e., no value). • prints out Pascal’s triangle to the standard output. • Employs two other functions, namely: – int choose(int n, int r); That chooses r from n – int factorial(int n); That calculates the factorial of n. Note: You are allowed — in fact, encouraged — to design and use any other functions as needed. Note: • The number of the rows is limited to integers between 0 and 13 inclusive. • If 0 is entered by the user, no triangle will be printed. • If a negative integer is entered by the user, the program terminates. • The number displayed in the last column must always be displayed at the start of the line. • Carefully calculate the spaces used between the numbers so that
Implement a C function, named triangle, that outputs Pascal’s triangle.
In general, the Pascal’s triangle can be represented as:
0C0
1C1 1C0
2C2 2C1 2C0
3C3 3C2 3C1 3C0
4C4 4C3 4C2 4C1 4C0
. . .
where nCr represents how many ways there are to choose r from n, not counting duplicates.
The formula used to calculate nCr can be written as:
nCr = n!/r!(n −r)!
where n! is the factorial of n.
The function triangle:
• is called by value where exactly one parameter (the number of rows of Pascal’s triangle)
is passed to it.
• returns void (i.e., no value).
• prints out Pascal’s triangle to the standard output.
• Employs two other functions, namely:
– int choose(int n, int r);
That chooses r from n
– int factorial(int n);
That calculates the factorial of n.
Note: You are allowed — in fact, encouraged — to design and use any other functions as needed.
Note:
• The number of the rows is limited to integers between 0 and 13 inclusive.
• If 0 is entered by the user, no triangle will be printed.
• If a negative integer is entered by the user, the program terminates.
• The number displayed in the last column must always be displayed at the start of the line.
• Carefully calculate the spaces used between the numbers so that the numbers are properly
aligned across rows.
![Expected
Enter the number of rows:
1
1
1
1
1
Enter the number of rows:
1
1
1
1
2
1
1
3
1
Enter the number of rows:
1
1
1
1
1
1
3
1
1
4
4
1
Enter the number of rows:
3.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F435c518f-3e96-46a0-9798-12c0b42c9d3e%2Ff3586401-6a18-4a2f-931b-c5f8f08ab148%2Fyty6two_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)