Write a program to calculate and print the factorial of a number using a for loop. The factorial of a number is the product of all integers up to and including that number, so the factorial of 4 is 4*3*2*1= 24.
<?php $n = 6; $x = 1; for($i=1;$i<=$n-1;$i++) { $x*=($i+1); } echo "The factorial of $n = $x"."\n"; ?>
Sample Output:
The factorial of 6 = 720
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer