PHP Find Factorial Of A Number

📔 : PHP 🔗
Copy Fullscreen Close Fullscreen
<?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 );
?>
Output
The factorial of 5 is: 120
The factorial of 10 is: 3628800

Related Topics :

Hey ! I'm Rahul founder of learnhindituts.com. Working in IT industry more than 4.5 years. I love to talk about programming as well as writing technical tutorials and blogs that can help to others .... keep learning :)

Get connected with me - LinkedIn Twitter Instagram Facebook