Introduction: What is an Fibonacci Series?
A series of numbers in which each number is the sum of the two preceding or previous numbers is called Fibonacci Series.
Parameters Needed
- a
- b
- c
- n
- i
Algorithm
Step 1: Start Step 2: Declare variable a, b, c, n, i Step 3: Initialize variable a=0, b=1 and i=2 Step 4: Read n from user Step 5: Print a and b Step 6: Repeat until i<=n : Step 6.1: c=a+b Step 6.2: print c Step 6.3: a=b, b=c Step 6.4: i=i+1 Step 7: Stop
Code
const number = parseInt(prompt('Enter the number of terms: ')); let n1 = 0, n2 = 1, nextTerm; console.log('Fibonacci Series:'); for (let i = 1; i <= number; i++) { console.log(n1); nextTerm = n1 + n2; n1 = n2; n2 = nextTerm; }
Output
