Return to Snippet

Revision: 34645
at October 26, 2010 13:39 by indra


Updated Code
//To calculate a factorial the simplest way and more optimized, you may use the following function

 Private Function Factorial(ByVal Num As Int64) As Int64
        Factorial = 1
        For i = 2 To Num
            Factorial *= Num
        Next
    End Function

//Please be aware that there is an inherent max to all factorial calculations. Based on x86 or x64. 
//Let alone the data types being supported. I used a Int64 instead of Integer because Integer is 
//actually a wrapper for Int32, which has a smaller min/max

//In some cases, you may want to use:

Private Function Factorial(ByVal Num As UInt64) As UInt64
        Dim i As UInt64
        Factorial = 1
        For i = 2 To Num
            Factorial *= Num
        Next
    End Function

//seeing as the UInt64 allows for a MUCH bigger maximum than the Int64 does. U stands for unsigned, 
//meaning its positive numbers only.

Revision: 34644
at October 26, 2010 13:39 by indra


Updated Code
//To calculate a factorial the simplest way and more optimized, you may use the following function

 Private Function Factorial(ByVal Num As Int64) As Int64
        Factorial = 1
        For i = 2 To Num
            Factorial *= Num
        Next
    End Function

//Please be aware that there is an inherent max to all factorial calculations. Based on x86 or x64. 
//Let alone the data types being supported. I used a Int64 instead of Integer because Integer is 
//actually a wrapper for Int32, which has a smaller min/max

In some cases, you may want to use:

Private Function Factorial(ByVal Num As UInt64) As UInt64
        Dim i As UInt64
        Factorial = 1
        For i = 2 To Num
            Factorial *= Num
        Next
    End Function

//seeing as the UInt64 allows for a MUCH bigger maximum than the Int64 does. U stands for unsigned, 
//meaning its positive numbers only.

Revision: 34643
at October 26, 2010 13:38 by indra


Updated Code
//To calculate a factorial the simplest way and more optimized, you may use the following function

 Private Function Factorial(ByVal Num As Int64) As Int64
        Factorial = 1
        For i = 2 To Num
            Factorial *= Num
        Next
    End Function

//Please be aware that there is an inherent max to all factorial calculations. Based on x86 or x64. 
//Let alone the data types being supported. I used a Int64 instead of Integer because Integer is actually a wrapper for Int32, which has a smaller min/max

In some cases, you may want to use:

Private Function Factorial(ByVal Num As UInt64) As UInt64
        Dim i As UInt64
        Factorial = 1
        For i = 2 To Num
            Factorial *= Num
        Next
    End Function

//seeing as the UInt64 allows for a MUCH bigger maximum than the Int64 does. U stands for unsigned, meaning its positive numbers only.

Revision: 34642
at October 26, 2010 13:38 by indra


Updated Code
//To calculate a factorial the simplest way and more optimized, you may use the following function

 Private Function Factorial(ByVal Num As Int64) As Int64
        Factorial = 1
        For i = 2 To Num
            Factorial *= Num
        Next
    End Function

//Please be aware that there is an inherent max to all factorial calculations. Based on x86 or x64. Let alone the data types being supported. I used a Int64 instead of Integer because Integer is actually a wrapper for Int32, which has a smaller min/max

In some cases, you may want to use:

Private Function Factorial(ByVal Num As UInt64) As UInt64
        Dim i As UInt64
        Factorial = 1
        For i = 2 To Num
            Factorial *= Num
        Next
    End Function

//seeing as the UInt64 allows for a MUCH bigger maximum than the Int64 does. U stands for unsigned, meaning its positive numbers only.

Revision: 34641
at October 26, 2010 13:37 by indra


Initial Code
'To calculate a factorial the simplest way and more optimized, you may use the following function

 Private Function Factorial(ByVal Num As Int64) As Int64
        Factorial = 1
        For i = 2 To Num
            Factorial *= Num
        Next
    End Function

'Please be aware that there is an inherent max to all factorial calculations. Based on x86 or x64. Let alone the data types being supported. I used a Int64 instead of Integer because Integer is actually a wrapper for Int32, which has a smaller min/max

In some cases, you may want to use:

Private Function Factorial(ByVal Num As UInt64) As UInt64
        Dim i As UInt64
        Factorial = 1
        For i = 2 To Num
            Factorial *= Num
        Next
    End Function

'seeing as the UInt64 allows for a MUCH bigger maximum than the Int64 does. U stands for unsigned, meaning its positive numbers only.

Initial URL
http://www.daniweb.com/forums/thread10589.html

Initial Description


Initial Title
Calculate Factorial

Initial Tags


Initial Language
VB.NET