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 ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)

Get connected with me. :) LinkedIn Twitter Instagram Facebook