1 개요[ | ]
- PHP factorial()
반복
PHP
Copy
function factorial($x) {
$result = 1;
for($i=2; $i<=$x; $i++) $result *= $i;
return $result;
}
echo factorial(4); # 24
Loading
재귀
PHP
Copy
function factorial($n) {
if( $n <= 1 ) return 1;
return $n * factorial($n-1);
}
echo factorial(4); # 24
Loading
2 같이 보기[ | ]
3 참고[ | ]
편집자 Jmnote Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.