Write a factorial program using for loop in php
Description:
Write a program to calculate factorial of a number using for loop in php.
<?php
$num = 3;
$factorial = 1;
for ($x=$num; $x>=1; $x--)
{
$factorial = $factorial * $x;
}
echo "The factorial of $num is $factorial";
?>
Tutorials Class - Output Window
The factorial of 3 is 6
Learn more about the similar topics:
Tutorials |
---|
PHP Loops |
Interview Questions & Answers |
---|
No Content Found. |