PHP program to print factorial of a number

PHP program to print factorial of a number:

The below program prints factorial of a number using a loop. The PHP echo statement is used to output the result on the screen. The factorial of a number can be calculated for positive integers only and is represented by n!.

n! = n*(n-1)*(n-2)*......*1
0! = 1

Example

<!DOCTYPE html>
<html>
<body>
 
<?php  
$n = 10;  
$f = 1;  
for ($i=$n; $i>=1; $i--)   
{  
$f = $f * $i;  
}  
echo "$n! = $f";  
?> 
 
</body>
</html>

Output

10! = 3628800
Please Share