The factorial of number n is multiplying given integer with the sequence of its descending positive integers. we denoted the factorial of a number n by n! in mathematics. Here I am writing factorial program in PHP..
Here are writing the PHP program to find a factorial of a number.
image source : google images
Example :-5! = 5*4*3*2*1 = 120
7! = 7*6*5*4*3*2*1 = 5040
Here are writing the PHP program to find a factorial of a number.
<?php
function factorial($number){
$factorial = 1;
for($x=$number;$x>=1;$x--){
$factorial = $factorial*$x;
}
return $factorial;
}
echo 'factorial is='.factorial(11);
?>
Output :- factorial is=3,99,16,800
Using the above program you can find the factorial of any positive integer in PHP.
Note: Only a member of this blog may post a comment.