Blog Tentang Informasi Tutorial Desain Web Dan Info Terkini

Array Fibonacci

Array Fibonacci

?html>
?head>?title>Deret Fibonacci?/title>?/head>
?body>
?script language = "javascript">
?!--
function fibonacci(n)
{
var i;
var array_fib = new Array();
array_fib.push(0);
array_fib.push(1);
for (i=0; i?n; i++)
{
array_fib.push(array_fib[0]+array_fib[1]);
array_fib.shift();
}
return array_fib[0];
}
for (i=0; i?=20; i++)
document.write("Fibonacci ("+i+")="+fibonacci(i) +"?br>");
//-->
?/script>
?/body>
?/html>

hasil setelah program dirunning adalah sebagai berikut :
Fibonacci (0)=0
Fibonacci (1)=1
Fibonacci (2)=1
Fibonacci (3)=2
Fibonacci (4)=3
Fibonacci (5)=5
Fibonacci (6)=8
Fibonacci (7)=13
Fibonacci (8)=21
Fibonacci (9)=34
Fibonacci (10)=55
Fibonacci (11)=89
Fibonacci (12)=144
Fibonacci (13)=233
Fibonacci (14)=377
Fibonacci (15)=610
Fibonacci (16)=987
Fibonacci (17)=1597
Fibonacci (18)=2584
Fibonacci (19)=4181
Fibonacci (20)=6765
Tag : MATA KULIAH
0 Komentar untuk "Array Fibonacci"

INFO NEWS UPDATE

loading...
Back To Top