If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
<?php
/*define a recursive function to calculate factorial of a number.
* @param int.
* return int.
*/
function find_fact($number)
{
if ($number == 0)
{
return 1;
}
/* Recursion */
$result = ( $number * find_fact( $number-1 ) );
return $result;
}
echo "The factorial of 5 is: " . find_fact( 5 ).'<br>';
echo "The factorial of 10 is: " . find_fact( 10 );
?>
The factorial of 5 is: 120 The factorial of 10 is: 3628800