Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
38
Task/Catalan-numbers/FreeBASIC/catalan-numbers.freebasic
Normal file
38
Task/Catalan-numbers/FreeBASIC/catalan-numbers.freebasic
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
Function factorial(n As UInteger) As UInteger
|
||||
If n = 0 Then Return 1
|
||||
Return n * factorial(n - 1)
|
||||
End Function
|
||||
|
||||
Function catalan1(n As UInteger) As UInteger
|
||||
Dim prod As UInteger = 1
|
||||
For i As UInteger = n + 2 To 2 * n
|
||||
prod *= i
|
||||
Next
|
||||
Return prod / factorial(n)
|
||||
End Function
|
||||
|
||||
Function catalan2(n As UInteger) As UInteger
|
||||
If n = 0 Then Return 1
|
||||
Dim sum As UInteger = 0
|
||||
For i As UInteger = 0 To n - 1
|
||||
sum += catalan2(i) * catalan2(n - 1 - i)
|
||||
Next
|
||||
Return sum
|
||||
End Function
|
||||
|
||||
Function catalan3(n As UInteger) As UInteger
|
||||
If n = 0 Then Return 1
|
||||
Return catalan3(n - 1) * 2 * (2 * n - 1) \ (n + 1)
|
||||
End Function
|
||||
|
||||
Print "n", "First", "Second", "Third"
|
||||
Print "-", "-----", "------", "-----"
|
||||
Print
|
||||
For i As UInteger = 0 To 15
|
||||
Print i, catalan1(i), catalan2(i), catalan3(i)
|
||||
Next
|
||||
Print
|
||||
Print "Press any key to quit"
|
||||
Sleep
|
||||
Loading…
Add table
Add a link
Reference in a new issue