Module Module1

    Sub Main()
        Dim num As Integer, i As Integer, fact As Integer = 1
        Console.WriteLine("www.ProgrammingPosts.blogspot.com")
        Console.WriteLine(vbLf & " >>VB.Net PROGRAM TO FIND FACTORIAL OF GIVEN NUMBER <<" & vbLf)
        Console.Write(vbLf & " Enter the Number whose Factorial you want: ")
        num = Convert.ToInt32(Console.ReadLine())
        For i = num To 2 Step -1
            'i is intializing with num value and  is decremented till 2
            'fact is updating with changing value of i
            fact = fact * i
        Next

        Console.WriteLine(vbLf & " The factorial of {0} is {1}." & vbLf & vbLf, num, fact)
        Console.ReadLine()
    End Sub

End Module

 

Sample Output :

VB.Net Factorial


Leave a Reply

Your email address will not be published.