tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
27
Task/Pascals-triangle/Java/pascals-triangle-2.java
Normal file
27
Task/Pascals-triangle/Java/pascals-triangle-2.java
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
public class Pas{
|
||||
public static void main(String[] args){
|
||||
//usage
|
||||
pas(20);
|
||||
}
|
||||
|
||||
public static void pas(int rows){
|
||||
for(int i = 0; i < rows; i++){
|
||||
for(int j = 0; j <= i; j++){
|
||||
System.out.print(ncr(i, j) + " ");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
public static long ncr(int n, int r){
|
||||
return fact(n) / (fact(r) * fact(n - r));
|
||||
}
|
||||
|
||||
public static long fact(int n){
|
||||
long ans = 1;
|
||||
for(int i = 2; i <= n; i++){
|
||||
ans *= i;
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue