Skip to content

Instantly share code, notes, and snippets.

@emanoelbarreiros
Created December 2, 2025 11:11
Show Gist options
  • Select an option

  • Save emanoelbarreiros/760748d64d06273a291a65648678b73e to your computer and use it in GitHub Desktop.

Select an option

Save emanoelbarreiros/760748d64d06273a291a65648678b73e to your computer and use it in GitHub Desktop.
Fibonacci iterativo
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