We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 628c144 commit d4f7eb7Copy full SHA for d4f7eb7
1 file changed
JavaScript Interview Programs/Generate Fibonacci.js
@@ -43,4 +43,15 @@ fibonacci(7);
43
// Output:
44
// 0 1 1 2 3 5 8
45
46
-
+// 2. Generate Fibonacci of a Number Using Recursion:
47
+function fibonacci(n) {
48
+ if (n <= 1) return n;
49
+ return fibonacci(n - 1) + fibonacci(n - 2);
50
+}
51
+// Print first N Fibonacci numbers
52
+let n = 7;
53
+console.log("Fibonacci using recursion:");
54
+for (let i = 0; i < n; i++) {
55
+ console.log(fibonacci(i));
56
57
+// Output:
0 commit comments