Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Function Factorial(n as Integer) as Integer \' Write code here to compute n! \'

ID: 3562643 • Letter: F

Question

Function Factorial(n as Integer) as Integer

' Write code here to compute n! '

Return the value n!

End Function

After you have written this Factorial function, add a Page_Load event handler that calls the function, displaying on the ASP.NET web page the values of 1! through 5!. Hint: The Factorial function will need to contain a looping construct from 1 to n, where, at each iteration, a variable is multiplied by the value of the looping variable.

I just need to know what is the factorial code because I have tried many times but no solutions.Please and thank you.

Explanation / Answer

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        For i = 1 To 5
            Response.Write(Convert.ToString(i) + "!: " + Convert.ToString(Factorial(i)) + "<br/>")
        Next

    End Sub

    Function Factorial(n As Integer) As Integer

        ' Write code here to compute n! '
        If (n > 1) Then
            Return n * Factorial(n - 1)
        Else
            Return n * 1
        End If

    End Function

OUTPUT

1!: 1
2!: 2
3!: 6
4!: 24
5!: 120