Last active
May 8, 2026 13:28
-
-
Save jeffersonchaves/12c7a042be3f5f4a2e7ccbe6ac49509e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| function somaDigitos($numero) | |
| { | |
| $soma = 0; | |
| while ($numero > 0) { | |
| $digito = $numero % 10; // pega o último dígito | |
| $soma += $digito; // soma o dígito | |
| $numero = $numero / 10; // remove o último dígito | |
| } | |
| return $soma; | |
| } | |
| // Teste | |
| echo somaDigitos(2004); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment