Computing a Factorial

nomad41

New member
Joined
May 1, 2006
Messages
2
Programming Experience
Beginner
The symbol N! represents the product of the first N positive integers. Thus 5! = 5 * 4 *3 * 2 * 1. This is called 5 factorial. The general equation is:
N! = N * (N - 1) * (N - 2) * ... * 1
When a result is defined in terms of itself, it is called a recursive definition. Construct a program that will accept a positive integer from a NumericUpDown control and then compute its factorial when a Button control is clicked. The recursive definition used in the program is as follows:
If N = 1, then N! = 1, otherwise N! = N * (N - 1)!

Anyone have any ideas?
 
From MSDN (Search Recursion)

VB.NET:
Function Factorial(ByVal N As Integer) As Integer
   If N <= 1 Then      ' Reached end of recursive calls.
      Return 1         ' N = 0 or 1, so climb back out of calls.
   Else                ' N > 1, so call Factorial again.
      Return Factorial(N - 1) * N
   End If
End Function
 
Back
Top