Project Euler 20

by Juan Alban Franco

HTML

n! means n × (n − 1) × ... × 3 × 2 × 1

For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800,
and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.

Find the sum of the digits in the number 100!


<p id = input></p>

JavaScript

/*var t = fact(100);
alert(t)
alert(t.toString())
*/
//var f = fact(10);
//var div = WhatPosition(f,10);
//alert(sumFact(f,div));

alert(Math.trunc(250/10));

function sumFact(_f,_div){
if (_div==1) {return 0}
else
	return _f%_div + sumFact(_f,(_div/10))
}


function WhatPosition(num,pos)
{
	if(num%pos == num){
		return pos
}
	else
		return WhatPosition(num,pos*10)
}

function fact(num){
if (num ==1){return 1}
else
{
	return num * fact(num-1)
}

}