Write a PHP script to calculate and print the factorial of a number using a for loop

Introduction

PHP is a server scripting language, and It is a powerful tool for making interactive and dynamic Web-pages. I have used WampServer 2.2 for following example.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. <?php
  2. $num = 5;
  3. $x = 1;
  4. for($i=1;$i<=$num-1;$i++)
  5. {
  6. $x*=($i+1);
  7. }
  8. echo "The Factorial of $num is: $x"."\n";
  9. ?>

Result

python language techstudy.org

     





Related Topics




Popular Posts