Last active
July 6, 2017 23:36
-
-
Save hertz1/2fefa3b94313c54bddbf0a4914f8beaa to your computer and use it in GitHub Desktop.
Multiplica um número pelo resultado da multiplicação anterior
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 | |
/** | |
* Multiplica um número pelo resultado da multiplicação anterior. | |
* Exercício proposto pela página "Asolucoesweb" (http://bit.ly/2tS4qj2) | |
* | |
* @var integer $base O número a ser multiplicado | |
* @var integer $iterations O número de vezes a ser interado | |
* @var integer $multiplier O resultado da multiplicação anterior | |
* @var integer $count O quantidade de vezes já iteradas | |
* | |
* @return string | |
*/ | |
function multiplyByLastResult($base, $iterations, $multiplier = 1, $count = 0) { | |
if ($count === $iterations) return; | |
$result = $base * $multiplier; | |
echo "Multiplicando $base x $multiplier = $result <br>"; | |
multiplyByLastResult($base, $iterations, $result, ++$count); | |
} | |
multiplyByLastResult(3, 10); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment