YavorGrancharov

N Factorial

Dec 2nd, 2017
1,620
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.52 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>First Steps Into PHP</title>
  6.  
  7. </head>
  8. <body>
  9. <form>
  10.     N: <input type="text" name="num" />
  11.     <input type="submit" />
  12. </form>
  13. <?php
  14.     if (isset($_GET['num'])) {
  15.         $res = 1;
  16.         $n = intval($_GET['num']);
  17.         if ($n == 0) {
  18.             echo "1";
  19.         }
  20.         else {
  21.             for ($x = 1; $x <= $n; $x++) {
  22.                 $res *= $x;
  23.             }
  24.         }
  25.         echo $res;
  26.     }
  27. ?>
  28. </body>
  29. </html>
Add Comment
Please, Sign In to add comment