//求1+2!+3!+...+20!的值
var sum = 0;
for(var i = 1 ; i <= 20 ; i++){
function factorial(i){
if(i == 1){
return 1;
}
return factorial ( i - 1 ) * i;
}
var ret=factorial(i);
sum += ret;
}
alert(sum);
//求1+2!+3!+...+20!的值
var sum = 0;
for(var i = 1 ; i <= 20 ; i++){
function factorial(i){
if(i == 1){
return 1;
}
return factorial ( i - 1 ) * i;
}
var ret=factorial(i);
sum += ret;
}
alert(sum);