Skip to content

Commit 6085b1f

Browse files
new method without recursion
1 parent e09c985 commit 6085b1f

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/main/java/com/thealgorithms/recursion/FibonacciSeries.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,20 @@ public static int fibonacci(int n) {
1818
return fibonacci(n - 1) + fibonacci(n - 2);
1919
}
2020
}
21-
}
21+
22+
23+
// n is the number upto which fibonacci sequence is required
24+
// for example n = 4 , output = 0 1 1 2
25+
public static void fibo(int n){
26+
int a = 0 ; int b = 1 ; int c =0;
27+
System.out.print(a+" "+b);
28+
for (int i = 2 ; i<n ; i++){
29+
c = a+b;
30+
System.out.print(" "+ c);
31+
a = b ;
32+
b = c ;
33+
}
34+
35+
}
36+
37+
}

0 commit comments

Comments
 (0)