Write a PHP program to print the factorial of a number
Factorial of a number n is defined by the product of all the numbers from 1 to n (including 1 and n).
Number Is 5
Get Factorial Steps
5*4*3*2*1
Output:
120
<?php
$number=6;
$factValue = 1;
for ($i=1; $i<=$number; $i++)
{
$factValue = $factValue * $i;
}
echo "Factorial of $number is $factValue";
?>
Factorial of 6 is 720
<?php
function getFactorial($number=""){
$factValue = 1;
for ($i=1; $i<=$number; $i++)
{
$factValue = $factValue * $i;
}
echo "Factorial of $number is $factValue";
}
getFactorial(8);
?>
Factorial of 8 is 40320
© 2024 Easy To Learning. All Rights Reserved | Design by Easy To Learning