php.php 351 B

12345678910111213141516171819
  1. <?php
  2. function nfact($n) {
  3. if ($n == 0) {
  4. return 1;
  5. }
  6. else {
  7. return $n * nfact($n - 1);
  8. }
  9. }
  10. echo "\n\nPlease enter a whole number ... ";
  11. $num = trim(fgets(STDIN));
  12. // ===== PROCESS - Determing the factorial of the input number =====
  13. $output = "\n\nFactorial " . $num . " = " . nfact($num) . "\n\n";
  14. echo $output;
  15. ?>