This website completely moved to new platform. For latest content, visit www.programmingposts.com

Search this Site

19 Aug 2013

VB.Net Program to Find Factorial of given Number

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 :