Friday, 20 April 2018

//Wap to print pascal triangle ?

import java.util.Scanner;

public class PascalTriangle {
public static void main(String[] args) {
int i,j,n,one=1;
    System.out.println("Enter No. of rows");
    Scanner s1=new Scanner(System.in);
    n=s1.nextInt();
    for(i=0;i<n;i++)
{
for(j=1;j<=n-i;j++)
    System.out.print(" ");
for(j=0;j<=i;j++)
{
if(i==0||j==0)
one=1;
else
one=one*(i-j+1)/j;
System.out.print(one);
System.out.print(" ");
}
System.out.println();
}
}
}


Image result for pascal triangle

No comments:

Post a Comment