02-17-2023, 08:58 PM
(This post was last modified: 02-17-2023, 09:02 PM by dcromley.
Edit Reason: note
)
Nice patterns. Nice checkerboard. Amazing what can be done in a few lines of code.
I like this -- having the program show what's going on with recursion:
I like this -- having the program show what's going on with recursion:
Code: (Select All)
_Title "Recursion Demo" ' dcromley
Screen _NewImage(1024, 768, 12)
Color 0, 15
Cls
Print Chr$(13) + "Finally, factorial(5)=" + Str$(factorial(5))
Function factorial (n)
Dim t ' t exists for the duration of THIS level of recursion
Print "Getting factorial(" + Str$(n) + ")"
If n = 1 Then
Print "factorial(1) = 1"
factorial = 1
Else
Print "Need factorial(" + Str$(n - 1) + ")"
t = factorial(n - 1)
Print "Got factorial(" + Str$(n - 1) + ") =" + Str$(t)
factorial = n * t
End If
End Function
___________________________________________________________________________________
I am mostly grateful for the people who came before me. Will the people after me be grateful for me?
I am mostly grateful for the people who came before me. Will the people after me be grateful for me?