Wednesday, 3 August 2016

Pascal Triangle

Question No:2 Pascal Triangle
i/p: 5

    1 

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

public static void main(String[] args) {

Scanner sc=new Scanner(System.in);
System.out.println("enter n value");
int n=sc.nextInt();
int number=1;
for(int i=0;i<=n;i++){
for(int j=0;j<=n-i;j++){
System.out.print(" ");
}
number=1;
for(int k=0;k<=i;k++){
System.out.print(number+" ");
number=number*(i-k)/(k+1);
}
System.out.println();
}
}

No comments:

Post a Comment

Featured post

All Logical Questions are Answered JumpInToIt