Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
18
Task/Pascals-triangle/Kotlin/pascals-triangle.kotlin
Normal file
18
Task/Pascals-triangle/Kotlin/pascals-triangle.kotlin
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
fun pas(rows: Int) {
|
||||
for (i in 0..rows - 1) {
|
||||
for (j in 0..i)
|
||||
print(ncr(i, j).toString() + " ")
|
||||
println()
|
||||
}
|
||||
}
|
||||
|
||||
fun ncr(n: Int, r: Int) = fact(n) / (fact(r) * fact(n - r))
|
||||
|
||||
fun fact(n: Int) : Long {
|
||||
var ans = 1.toLong()
|
||||
for (i in 2..n)
|
||||
ans *= i
|
||||
return ans
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) = pas(args[0].toInt())
|
||||
Loading…
Add table
Add a link
Reference in a new issue