Hello.
How I can calculate the factorial of a number?
Please, helpe me
Thanks
Offline
This should approximate factorials:
e^(n*ln(n) - n + (ln(2*π*n))/2) or e^(n*ln(n) - n + ln(√(2*π*n)))
To find out the exact, set the "inputNumber" variable to the number who's factorial you want to find, run the code below, and the answer should be in the "result" variable. This should work for all whole numbers.
set [result v] to (1) set [loop v] to (1) repeat ((inputNumber)-(1)) change [loop v] by (1) set [result v] to ((result)*(loop)) end
Last edited by MoreGamesNow (2013-03-24 20:08:52)
Offline
I actually found a really cool factorial calculator a while ago: http://scratch.mit.edu/projects/Molybdenum/2630470
Offline
Hyperbola wrote:
I actually found a really cool factorial calculator a while ago: http://scratch.mit.edu/projects/Molybdenum/2630470
If you'll be calculating large factorials (i.e. factorials that are so large that Scratch would normally report them as "infinity") I'd go with Molybdenum's project. The script above is simpler, but, given the maximum size of Scratch variables, has its limits.
Offline
Thank you so much it works
Offline