|
Factorial function
To get the factorial of the integer 5 you use the sum 5*4*3*2*1
which of course gives you 120 . If you chose the Factorial of
3 this would be 3*2*1 .
If the number is less than or equal to 1 then the Factorial
function returns 1 and no more recursion takes place. If the
number is greater than 1 then we use the following statement
Factorial = intNumber * Factorial(intNumber - 1)
Here is our function
<%
Function Factorial(ByVal intNumber)
If intNumber <= 1 Then
Factorial = 1
Else
Factorial = intNumber * Factorial(intNumber - 1)
End If
End Function
%>
And here we test the function with 2 values 5 and then 10
<%
Response.Write ("Factorial of 5 is " & Factorial(5))
Response.Write ("<br>")
Response.Write ("Factorial of 7 is " & Factorial(7))
%>
|