/ Published in: VB.NET
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//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.
URL: http://www.daniweb.com/forums/thread10589.html