Skip to content

Commit 0cca19f

Browse files
authored
Merge pull request ghostmkg#107 from vaibhavv144/main
Fibonacci_method
2 parents d3e3f68 + 14be2d1 commit 0cca19f

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Fabo.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
public class Fabo {
2+
public static int fibonacciRecursion(int n,int[]arr){
3+
4+
/* if(n == 0){
5+
return 0;
6+
}
7+
if(n == 1 || n == 2){
8+
return 1;*/
9+
10+
if(n<=1){
11+
return n;
12+
}
13+
if(arr[n]!=0){
14+
return arr[n];
15+
}
16+
17+
18+
int ans=fibonacciRecursion(n-2,arr) + fibonacciRecursion(n-1,arr);
19+
return arr[n]=ans;
20+
21+
}
22+
23+
public static void main(String args[]) {
24+
int maxNumber = 6;
25+
System.out.print("Fibonacci Series of " + maxNumber + " numbers: ");
26+
int []arr=new int[maxNumber+1];
27+
int ans=fibonacciRecursion(maxNumber,arr);
28+
System.out.println(ans);
29+
30+
}
31+
}

0 commit comments

Comments
 (0)