-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpascalstriangle.java
More file actions
31 lines (30 loc) · 950 Bytes
/
pascalstriangle.java
File metadata and controls
31 lines (30 loc) · 950 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.util.Scanner;
public class pascalstriangle {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("enter n ");
int n = sc.nextInt();
System.out.println("pascal ");
int [][] ans = pascal(n);
print(pascal(n));
}
static void print(int[][] vib) {
for (int i = 0; i < vib.length; i++) {
for (int j = 0; j < vib[i].length; j++) {
System.out.print(vib[i][j] + " ");
}
System.out.println();
}
}
static int [][] pascal(int n ){
int [][] vib = new int [n][];
for (int i = 0 ; i <n; i ++) {
vib [i] = new int [i+1];
vib[i][0] = vib [i][i] = 1;
for (int j =1; j <i; j++) {
vib [i][j] = vib[i-1][j] + vib [i-1][j-1];
}
}
return vib;
}
}