Answer to Question #194479 in Visual Basic for anna

Question #194479

Professor Juarez wants to calculate the factorial numbers in his mathematic class. As an IT student, you are the best candidate to help him solve his problem. With the aid of your Visual basic expertise, write a program that will print the factorial of a number by defining a method named 'Factorial'. You should name your program Factorial. Factorial of any number n is represented by n! and is equal to 1*2*3*....*(n-1)*n. E.g.- 4! = 1*2*3*4 = 24 3! = 3*2*1 = 6 2!=2*1=2 Also, 1! = 1, 0! = 0


1
Expert's answer
2021-05-17T13:29:40-0400
Module Module1

    Sub Main()
        'Get the number
        Console.Write("Enter the number: ")
        Dim number As Int64 = Int64.Parse(Console.ReadLine())
        'Display the factorial
        Console.WriteLine("{0}! = {1}", number, Factorial(number))
        Console.ReadLine()
    End Sub


    ''' <summary>
    ''' This functon calculates Factorial
    ''' </summary>
    ''' <param name="number"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function Factorial(ByVal number As Int64) As Int64
        If number <= 0 Then
            Return 0
        ElseIf number <= 1 Then
            Return 1
        Else
            Return number * Factorial(number - 1)
        End If
    End Function
End Module

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS