We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents b2599e1 + 33c5251 commit cb39de2Copy full SHA for cb39de2
fibonacci_number/FibonacciNumber.js
@@ -0,0 +1,34 @@
1
+function fibonacci(p) {
2
+ if(p === 1 || p === 2) {
3
+ return p-1; // base case
4
+ } else {
5
+
6
+ let a = 0;
7
+ let b = 1;
8
+ // 0 1 1 2 3 5 8 ...
9
+ let fib = 0;
10
+ for(var i = 2 ; i < p ; i = i + 1) {
11
+ fib = a + b;
12
+ a = b;
13
+ b = fib;
14
+ }
15
16
+ return fib;
17
18
+}
19
20
+function main() {
21
+ const readline = require('readline').createInterface({
22
+ input: process.stdin,
23
+ output: process.stdout
24
+ });
25
26
+ readline.question("Enter value of n ", n => {
27
+ console.log(fibonacci(n));
28
+ readline.close()
29
30
31
32
+main();
33
34
0 commit comments