forked from adityabiswal2147207/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpascals.java
More file actions
32 lines (29 loc) · 783 Bytes
/
Copy pathpascals.java
File metadata and controls
32 lines (29 loc) · 783 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
32
//creating a class pascals
public class pascals {
static int factorial(int n) {
//declaring the int datatype variable:->
int f;
for(f = 1; n > 1; n--){
f *= n;
}
return f;
}
static int adi(int n,int r) {
return factorial(n) / ( factorial(n-r) * factorial(r) );
}
//creating a static void main function
public static void main(String args[]){
System.out.println("The pascals triangle is below:--->");
int n, i, j;
n = 5;
for(i = 0; i <= n; i++) {
for(j = 0; j <= n-i; j++){
System.out.print(" ");
}
for(j = 0; j <= i; j++){
System.out.print(" "+adi(i, j));
}
System.out.println();
}
}
}