Last active
December 31, 2015 12:09
-
-
Save purushothblog/7984586 to your computer and use it in GitHub Desktop.
Check the given number is Fibonacci and find the next number in Fibonacci sequence.
This file contains 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
var n = 4, fib; | |
var a = (5 * Math.pow(n, 2) + 4) | |
var b=(5 * Math.pow(n, 2) - 4 ) | |
var result = Math.sqrt(a) % 1==0; | |
var res = Math.sqrt(b) % 1==0; | |
//fixed this line | |
if(result || res == true) // checks the given input is fibonacci series | |
{ | |
fib=Math.round(n* 1.618); // finds the next fibonacci series of given input | |
console.log("The next Fibonacci number is " + fib); | |
} | |
else | |
{ | |
console.log("The given number is not a fibonacci number"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment