Created
August 8, 2021 14:45
-
-
Save neilkerman/597e35af0e8ba919c4fe84f257a3227c to your computer and use it in GitHub Desktop.
Fibonacci Series
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Javascript program to print the fibonacci series. Coded by Samay Bhattacharyya. | |
| //Importing the readline library to read a line from console | |
| const readline = require("readline"); | |
| const rl = readline.createInterface({ | |
| input: process.stdin, | |
| output: process.stdout, | |
| }); | |
| //Function to print Fibonacci Series | |
| var fibonacci = (n) => { | |
| let a = 0, b = 1; | |
| while (n-- > 0) { | |
| process.stdout.write(`${a}, `); | |
| b = a + b; | |
| a = b - a; | |
| } | |
| } | |
| //Using readline library to take input and run the function | |
| rl.question("Enter a number: ", function (num) { | |
| console.log(`Fibonacci Series:\n`); | |
| if(isNaN(num)){console.log("Kindly enter a number");rl.close();} | |
| fibonacci(num); | |
| rl.close(); | |
| }); | |
| //Use node fibonacci.js to run the program |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment