tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
34
Task/Catalan-numbers/VBA/catalan-numbers.vba
Normal file
34
Task/Catalan-numbers/VBA/catalan-numbers.vba
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
Public Sub Catalan1(n As Integer)
|
||||
'Computes the first n Catalan numbers according to the first recursion given
|
||||
Dim Cat() As Long
|
||||
Dim sum As Long
|
||||
|
||||
ReDim Cat(n)
|
||||
Cat(0) = 1
|
||||
For i = 0 To n - 1
|
||||
sum = 0
|
||||
For j = 0 To i
|
||||
sum = sum + Cat(j) * Cat(i - j)
|
||||
Next j
|
||||
Cat(i + 1) = sum
|
||||
Next i
|
||||
Debug.Print
|
||||
For i = 0 To n
|
||||
Debug.Print i, Cat(i)
|
||||
Next
|
||||
End Sub
|
||||
|
||||
Public Sub Catalan2(n As Integer)
|
||||
'Computes the first n Catalan numbers according to the second recursion given
|
||||
Dim Cat() As Long
|
||||
|
||||
ReDim Cat(n)
|
||||
Cat(0) = 1
|
||||
For i = 1 To n
|
||||
Cat(i) = 2 * Cat(i - 1) * (2 * i - 1) / (i + 1)
|
||||
Next i
|
||||
Debug.Print
|
||||
For i = 0 To n
|
||||
Debug.Print i, Cat(i)
|
||||
Next
|
||||
End Sub
|
||||
Loading…
Add table
Add a link
Reference in a new issue