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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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.

 

 

Enter the number of rows: 3
1
1
1
1
2
1
Enter the number of rows: 4
1
1
1
1
2
1
1
3
3
1
Enter the
number of rows: 5
1
1
1
1
2
1
3
3
1
4
6
4 1
1
1
Transcribed Image Text:Enter the number of rows: 3 1 1 1 1 2 1 Enter the number of rows: 4 1 1 1 1 2 1 1 3 3 1 Enter the number of rows: 5 1 1 1 1 2 1 3 3 1 4 6 4 1 1 1
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education