Question No:2 Pascal Trianglei/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