factorial:-

The factorial of a number is the function that multiplies the number by every natural number below it. Symbolically, factorial can be represented as "!". So, n factorial is the product of the first n natural numbers and is represented as n!


For example:-

5!=1*2*3*4*5=120


Alogritham:-

Step 1: Start
Step 2: Declare Variable n, fact, i
Step 3: Read number from User
Step 4: Initialize Variable fact=1 and i=1
Step 5: Repeat Until i<=number
            5.1 fact=fact*i
            5.2 i=i+1
Step 6: Print fact
Step 7: Stop


code:-

<?php
$num = 5;
$x = 1;
for($i=1;$i<=$num-1;$i++)
{
 $x*=($i+1); 
}
echo "The Factorial of  $num is: $x";
?>

output:-

The Factorial of  5 is: 120

Post a Comment

If you have any doubts, Please let me know
Thanks!

Previous Post Next Post