How to calculate factorial in VB.NET

1 Answer

0 votes
Imports System.IO

Module Module1

    Sub Main()

        Dim n As Integer = 5, fact As Integer = 1, i As Integer = 1

        Try
            For i = 1 To n
                fact *= i
            Next

            Console.WriteLine(fact)

        Catch ex As Exception
            Console.WriteLine(ex.Message)
        End Try

    End Sub
   

    ' run:
    ' 
    ' 120

End Module


answered May 5, 2015 by avibootz
...