PHP Program to Find Factorial of a Number using For loop
ADVERTISEMENTS
PHP program to find factorial of a number using for loop. In this article, you will learn how to make a php program to find factorial of a number using for loop.
Factorial Number Formula
Factorial of x (n!) = 1 * 2 * 3 * 4....n
Source Code
<?php
// PHP Program to Find Factorial of a Number using For loop
$x = 9;
$f = 1;
// $x - To store the input number
// $f - To store the factorial value
if ($x > 0) {
for ($i = 1; $i <= $x; $i++) {
$f *= $i;
}
echo "Factorial of " . $x . " = " . $f . "\n";
} else {
echo "Sorry, The input number should be positive number& it's greater than 0!\n";
}
?>
Output
Factorial of 9 = 362880