+ 8

Factorial Challenge

Make a program that can calculate the factorial of any number and try to make it as fast as possible. You can make it in any language.

21st Oct 2017, 10:21 AM
johan beimers
johan beimers - avatar
7 Answers
+ 7
This would work with ANY number, and by ANY I mean also decimal ones: var g = 7; var C = [0.99999999999980993, 676.5203681218851, -1259.1392167224028,771.32342877765313, -176.61502916214059, 12.507343278686905, -0.13857109526572012, 9.9843695780195716e-6, 1.5056327351493116e-7]; function gamma(z){ if(z < 0.5){ return Math.PI/(Math.sin(Math.PI*z)*gamma(1-z)); }else{ z -= 1; var x = C[0]; for(var i = 1; i < g+2; i++){ x += C[i]/(z+i); } var t = z+g+0.5; return Math.sqrt(2*Math.PI)*Math.pow(t,(z+0.5))*Math.exp(-t)*x; } } var fact = function(x){ if(x == 0){ return 1; } return x*gamma(x); } alert(fact(1/2));
21st Oct 2017, 12:30 PM
Dapper Mink
Dapper Mink - avatar
+ 9
Javascript: var fact = function(n){ if(n == 0){ return 1; } return n*fact(--n); }
21st Oct 2017, 10:31 AM
Dapper Mink
Dapper Mink - avatar
22nd Oct 2017, 3:12 PM
Dragon Slayer Xavier
Dragon Slayer Xavier - avatar
+ 2
https://code.sololearn.com/c7OKn1aMi2zu/?ref=app
31st Oct 2017, 4:50 AM
Adib Attie
Adib Attie - avatar
17th Nov 2017, 9:27 AM
#RahulVerma
#RahulVerma - avatar
+ 1
https://code.sololearn.com/ci11y1PeLHvj/?ref=app Factorial more than 20 just tried simply ...😃😃
21st Dec 2018, 4:04 PM
Soniya Kulkarni
Soniya Kulkarni - avatar
31st Dec 2018, 11:29 PM
Ahmad Ali
Ahmad Ali - avatar