Pascal's Triangle Using JAVA
In mathematics, Pascal's triangle is a triangular array of the binomial coefficients. In much of the Western world it is named after French mathematician Blaise Pascal, although other mathematicians studied it centuries before him in India, Iran, China, Germany, and Italy.
The rows of Pascal's triangle (sequence A007318 in OEIS) are conventionally enumerated starting with row n = 0 at the top (the 0th row). The entries in each row are numbered from the left beginning with k = 0 and are usually staggered relative to the numbers in the adjacent rows. Having the indices of both rows and columns start at zero makes it possible to state that the binomial coefficient
appears in the nth row and kth column of Pascal's triangle. A simple construction of the triangle proceeds in the following manner: In row 0, the topmost row, the entry is
(the entry is in the zeroth row and zeroth column). Then, to construct the elements of the following rows, add the number above and to the left with the number above and to the right of a given position to find the new value to place in that position. If either the number to the right or left is not present, substitute a zero in its place. For example, the initial number in the first (or any other) row is 1 (the sum of 0 and 1), whereas the numbers 1 and 3 in the third row are added to produce the number 4 in the fourth row.
![\tbinom{n}{k}](https://upload.wikimedia.org/math/8/4/8/8482b29cc0af31fa35ff6bf04200b265.png)
![\tbinom{0}{0} = 1](https://upload.wikimedia.org/math/9/a/a/9aa1f928142f5c6e9463f5603c21b59d.png)
This construction is related to the binomial coefficients by Pascal's rule, which says that if
then
for any non-negative integer n and any integer k between 0 and n.
Pascal's triangle has higher dimensional generalizations. The three-dimensional version is called Pascal's pyramid or Pascal's tetrahedron, while the general versions are called Pascal's simplices.
Program Using JAVA:
public class pascal{
public static void main(String args[]){
int row=10;
for(int i=0;i<row;i++){
int no=1;
System.out.format("%"+(row-i)*2+"s","");
for(int j=0;j<=i;j++){
System.out.format("%4d",no);
no=no*(i-j)/(j+1);
}
System.out.println();
}
}
}
No comments:
Post a Comment