Factorial / Combination ??????????
Why isn't there and math function in VB for finding the factorial of a number ??????
Actually i need to find the following value:
mCn , i.e, m choose n, and the formula for that is
m factorial / (m-n) factorial * n factorial
n and m always >=1 , How can this be done ???????
Any ideas/codes/comments highly appreciated....,
ashky.
Factorials grows more than exponentially
In fact to calculate mCn you won't need factorials, most important you are limited to the hardware meaning CPU power.
Guv Posted two approaches the first which is simplification of the the expression with factorials and the second which can handle larger values on n*m but is limited to floating point calculation.
52! / 47! * 5! = 52*51*50*49*48 / 5*4*3*2*1
(52/5)*(51/4)*(50/3)*(49/2)*(48/1).
something like:
Code:
X=1
for M=M-N to M
X*=C/N //or X*=C and Y*=N and finally X/=Y for the first alternative
M--
next