Created
September 6, 2014 06:53
-
-
Save sharmaabhinav/fb96becdec426a6a6898 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 class HelloWorld{ | |
public static void main(String []args){ | |
int arr[] = new int[13]; | |
fab(13, arr); | |
} | |
static int fab(int n, int arr[]){ | |
if (n == 1 || n == 2 && arr[n - 1] == 0){ | |
arr[n - 1] = 1; | |
System.out.println(1); | |
return 1; | |
} | |
if (arr[n - 1] != 0 ){ | |
return arr[n - 1]; | |
}else{ | |
arr[n - 1] = fab(n - 2, arr) + fab(n - 1, arr); | |
System.out.println(arr[n - 1]); | |
return arr[n - 1]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment