-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrianguloPascal.java
More file actions
31 lines (26 loc) · 879 Bytes
/
Copy pathTrianguloPascal.java
File metadata and controls
31 lines (26 loc) · 879 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 TrianguloPascal {
public static void main(String[] args) {
Scanner ler = new Scanner(System.in);
System.out.print("Qual o tamanho do triangulo de pascal? ");
int nlinhas = ler.nextInt();
int tpascal[][];
tpascal = new int[nlinhas][nlinhas];
for (int x = 0; x < nlinhas; x++) {
System.out.println();
for (int y = 0; y <= x; y++) {
if (y == 0) {
tpascal[x][y] = 1;
}
if (x == y) {
tpascal[x][y] = 1;
}
if ((y != 0) & (x != y)) {
tpascal[x][y] = tpascal[x - 1][y - 1] + tpascal[x - 1][y];
}
System.out.print(tpascal[x][y] + " ");
}
}
System.out.println("\n");
}
}