Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created February 5, 2019 03:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/1087829b8222a3b7fb58b265bf8aae7d to your computer and use it in GitHub Desktop.
Save parzibyte/1087829b8222a3b7fb58b265bf8aae7d to your computer and use it in GitHub Desktop.
/**
* Sucesión fibonacci iterativo en Java
*
* @author parzibyte
*/
public static long fibonacci(long posicion) {
long siguiente = 1, actual = 0, temporal = 0;
for (long x = 1; x <= posicion; x++) {
// Si no quieres imprimirla, comenta la siguiente línea:
System.out.print(actual + ", ");
temporal = actual;
actual = siguiente;
siguiente = siguiente + temporal;
}
// Si no quieres imprimirla, comenta la siguiente línea:
System.out.println(actual);
return actual;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment