Question
Pascal's Triangle is an array of numbers that looks like this: 1 1 1 1 2 1 1 3 3 1 1 4 6 4
Pascal's Triangle is an array of numbers that looks like this:
1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 6 15 20 15 6 1 1 7 21 35 35 21 7 1
In this triangle, each entry is the sum of the two entries immediately above it. For example, in the last row, the 7 is the sum of the 1 and 6 above it, and the 21 is the sum of the 6 and 15 just above it.
Number the rows starting at zero. (So the peak of the triangle is in rows zero.) Notice that the row number is the second entry in each row.
Number the columns starting at zero. (So the beginning 1 in each row is in column zero.) Then the entries in the triangle are given by:
- tri(row, 0) = 1
- if row==col, tri(row, col) = 1
- otherwise, tri(row, col) = tri(row-1, col-1) + tri(row-1, col)
Write a Java method that implements this definition (10 marks) .
Then write a method that prints out the first N rows of the triangle (10 marks).
Write a main() method that asks the user for row and column number and then writes out the corresponding entry and prints out the triangle (6 marks) .
To start, write out each row of the triangle starting in column 1. Once that is working, write out the triangle with each row centered above the next.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started