Created
September 12, 2018 23:46
-
-
Save Kiwipup/a5e77b39f159813b31ebfa0955e4332b to your computer and use it in GitHub Desktop.
First factorial in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function FirstFactorial($num) { | |
// code goes here | |
//when the value of $num is less than or equal to 1, the function will terminate | |
if($num <= 1){ | |
return 1; | |
} | |
/* the function will call itself repeatedly, each time multiplying the value | |
of $num by its own value -1 until the condition of the | |
previous if statement becomes true */ | |
else{ | |
return $num * FirstFactorial($num -1); | |
} | |
} | |
// keep this function call here | |
echo FirstFactorial(fgets(fopen('php://stdin', 'r'))); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks good.