Created
February 11, 2016 13:57
-
-
Save NEbere/0e5dd799a9607de1ea08 to your computer and use it in GitHub Desktop.
The factorial of a given number
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 factorial($n) { | |
$factorial = 1; | |
for($i = $n; $i >= 1; $i--){ | |
$factorial = $factorial * $i; | |
} | |
echo "Factorial of $n is $factorial"; | |
} | |
//calling the function | |
factorial(5); | |
//returns 120 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment