Created
November 6, 2011 18:56
-
-
Save renatoargh/1343314 to your computer and use it in GitHub Desktop.
This file contains 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 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