Easiest way to do factorials is through recursion...I've added a code snippet which can be found
here. It takes the number for which you want to get the factorial and then returns the factorial value. I used double because factorials have a tendency to grow extremely quickly.
So your code would look something like this:
vb
Private Function Factorial(ByVal number As Double) As Double
If number <= 1 Then
Return (1)
Else
Return number * Factorial(number - 1)
End If
End Function
Private Sub factorials(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim douFactorial as Double = Factorial(15)
lblNumberFactorial.Text = douFactorial.ToString
End Sub
If you wanted to output the value each time the function recurses through...just add the line underneath the
CODE
Return number * Factorial(number - 1)
This post has been edited by nofear217: 20 Aug, 2008 - 09:43 AM