We are going to create a source code that prints the Pascal Triangle.

A Pascal Triangle is not just a big triangular pattern of numbers. There are two major areas where Pascal’s Triangle is used: Algebra and Probability/Combinatorics.

Source Code:

/* Program to print Inverted Pascal Triangle*/
import java.util.*;
class NumPascal
{
public static void main()
{
Scanner inp=new Scanner(System.in);
System.out.print("\n Enter Size Limit: ");
int n=inp.nextInt();
int i,j,x=1;
System.out.println("Pascal Triangle: \n");

for(i=1;i<=n;i++)
{
for(j=n;j>i;j--)
{
System.out.print(" ");
}
x=1;
for(j=1;j<=i;j++)
{
System.out.print(j+" ");
x=x*(i-j)/(j+1);
}
System.out.println();
}

}
}

Output:

Enter Size Limit: 6
Pascal Triangle: 

     1 
    1 2 
   1 2 3 
  1 2 3 4 
 1 2 3 4 5 
1 2 3 4 5 6

[yuzo_views]



CopyRight © 2019

CopyRight © 2019