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