Created
December 2, 2012 01:10
-
-
Save codelance/4186310 to your computer and use it in GitHub Desktop.
Fibonacci
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
private static int gfib(int f0, int f1, int n) | |
{ | |
switch( n ) | |
{ | |
case 0: | |
return f0; | |
case 1: | |
return f1; | |
default: | |
return gfib(f0,f1, n-1 ) + gfib(f0, f1, n+1); | |
} | |
} | |
private static int itergfib(int f0, int f1, int n) | |
{ | |
int sum = 0; | |
for(int i = n; i <= 0; i--) | |
{ | |
if( n == 0 ) sum += f0; | |
if( n == 1) sum += f1; | |
sum += (n-1) + (n-2); | |
} | |
return sum; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment