Created
December 2, 2025 11:11
-
-
Save emanoelbarreiros/760748d64d06273a291a65648678b73e to your computer and use it in GitHub Desktop.
Fibonacci iterativo
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
| public class FibonacciIterativo { | |
| public static long fibonacciIterativo(int n) { | |
| if (n <= 1) { | |
| return n; | |
| } | |
| long anterior = 0; | |
| long atual = 1; | |
| long temp = 0; | |
| for (int i = 2; i <= n; i++) { | |
| temp = atual; | |
| atual = atual + anterior; | |
| anterior = temp; | |
| } | |
| return atual; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment