Computer Science, asked by rounick3614, 11 months ago

Sum of the fibonacci series less than 100 using javascript

Answers

Answered by sreekanthmishra
0

Answer:

var fib = function(n) {

 if (n === 1) {

   return [0, 1];

 } else {

   var arr = fib(n - 1);

   arr.push(arr[arr.length - 1] + arr[arr.length - 2]);

   return arr;

 }

};

console.log(fib(8));

Explanation:

The sequence follows the rule that each number is equal to the sum of the antedating two figures. The Fibonacci sequence begins with the following 14 integers 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233. Each number, starting with the third, adheres to the specified formula.

#SPJ3

Answered by hemakumar0116
0

Answer: function(n) var fib

if (n === 1) {

[0, 1] return; } else {

fib(n - 1) var arr

(arr[arr.length - 1] + arr[arr.length - 2]);

revert arr;}};

console.log(fib(8));

Explanation:

The sequence adheres to the rule that each number is equal to the sum of the two preceding figures. The Fibonacci sequence starts with 14 integers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233. Each number, beginning with the third, follows the prescribed formula.

function as a variable (n) if (n === 1), return [0, 1]; otherwise var arr = fib(n – 1); arr.push (arr[arr.length – 1] + arr[arr.length – 2]); return arr;console.log(fib(8));

#SPJ2

Similar questions