Recursive Factorial
PHP
Medium
3 views
Problem Description
Compute n! using recursion (n
Input Format
One integer n.
Output Format
One integer factorial.
Official Solution
<?php
$inputText=trim(stream_get_contents(STDIN));
if($inputText==='') exit;
$n=intval($inputText);
function fact($n){
if($n<=1) return 1;
return $n*fact($n-1);
}
echo fact($n);
?>
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!