Last active
March 10, 2016 10:02
-
-
Save grisza12/1624be68a1a4a4b6f979 to your computer and use it in GitHub Desktop.
oxjVRM
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
<body> | |
<input id="wartosc" type="number" /> | |
<button onclick="myFunction()">Fibonnaci</button> | |
</body> |
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
function myFunction(){ | |
var x = document.getElementById("wartosc").value; | |
document.write(fib(x)); | |
} | |
function fib(n) { | |
var f1 = 1; | |
var f2 = 1; | |
var tmp = 0; | |
document.write(); | |
var start = new Date().getTime(); | |
for (var i = 2; i < n; i++) { | |
tmp = f1 + f2; | |
f1 = f2; | |
f2 = tmp; | |
} | |
var stop = new Date().getTime(); | |
var czas = stop - start; | |
document.write("liczba: "+n+" ciągu fibonnaciego - " +tmp+" Czas wykonania : " + czas + "s "); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment