Skip to content

Instantly share code, notes, and snippets.

@renatoargh
Created November 6, 2011 18:56
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 renatoargh/1343314 to your computer and use it in GitHub Desktop.
Save renatoargh/1343314 to your computer and use it in GitHub Desktop.
public static Int32 FibonacciR(Int32 n)
{
if (n == 0 || n == 1)
return n;
else
return FibonacciR(n - 1) + FibonacciR(n - 2);
}
public static Int32 FibonacciI(Int32 n)
{
if (n == 0 || n == 1)
return n;
Int32 anterior = 1, anteAnterior = 0, acumulador = 0;
for (int i = 2; i <= n; i++)
{
acumulador = anteAnterior + anterior;
anteAnterior = anterior;
anterior = acumulador;
}
return acumulador;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment