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 :

Rahul Kumar

Rahul Kumar

Hi ! My name is Rahul Kumar Rajput. I'm a back end web developer and founder of learnhindituts.com. I live in Uttar Pradesh (UP), India and I love to talk about programming as well as writing technical tutorials and tips that can help to others.

Get connected with me. :) LinkedIn Twitter Instagram Facebook