Factorials
Using a for loop.
Public Function Factorial(ByVal iValue As Integer) As Long
Dim fact As Long
Dim icount As Integer
fact = 1
For icount = 1 To iValue
fact = icount * fact
Next icount
Factorial = fact
End Function
Using a recursive function.
Public Function FactorialR(ByVal iValue As Integer) As Long
If ( (iValue = 0) Or (iValue = 1) ) Then
FactorialR = 1
Else
FactorialR = FactorialR(iValue - 1) * iValue
End If
End Function
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext