php計算1到8的階乘1?
php計算1到8的階乘1!+2!+3!+·····+8
每個語言必備階乘,代碼如下
$sum = 0;
for ($i = 1; $i < 9; $i++) {
$sum += jc($i);
}
echo $sum
function jc($num){
$tmp = 1;
$tmp2 = $tmp;
for ($i=1; $i < $num; $i++) {
if( $tmp < $num){
$tmp2 *= ($tmp+1);
++$tmp;
}
}
return $tmp2;
}
上一篇advan耳機怎么樣