Last active
April 16, 2017 04:29
-
-
Save mklemersson/25482a84b330d2c300b47231fb678ebd to your computer and use it in GitHub Desktop.
php - desafio fatorial
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 fatorial($n) | |
{ | |
if ($n < 2) { // verifica se o '$n' atual e menor que 2 para que a recursao pare | |
return 1; // retorna o valor do caso base | |
} else { | |
return $n * fatorial($n-1); // faz a chamada recursiva para achar o fatorial do numero informado inicialmente | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment