32 lines
621 B
Plaintext
32 lines
621 B
Plaintext
' FB 1.05.0 Win64
|
|
|
|
Function factorial(n As Integer) As Integer
|
|
If n < 1 Then Return 1
|
|
Dim product As Integer = 1
|
|
For i As Integer = 2 To n
|
|
product *= i
|
|
Next
|
|
Return Product
|
|
End Function
|
|
|
|
Function binomial(n As Integer, k As Integer) As Integer
|
|
If n < 0 OrElse k < 0 OrElse n <= k Then Return 1
|
|
Dim product As Integer = 1
|
|
For i As Integer = n - k + 1 To n
|
|
Product *= i
|
|
Next
|
|
Return product \ factorial(k)
|
|
End Function
|
|
|
|
For n As Integer = 0 To 14
|
|
For k As Integer = 0 To n
|
|
Print Using "####"; binomial(n, k);
|
|
Print" ";
|
|
Next k
|
|
Print
|
|
Next n
|
|
|
|
Print
|
|
Print "Press any key to quit"
|
|
Sleep
|