ARRAY (1)
?html>
?head>
?title>Belajar Array?/title>
?/head>
?body>
?script language = "JavaScript">
?!--
var data_ku = new Array ("Saya","Sedang","Senang");
for (i=0; i?3; i++)
{
document.write(data_ku[i] + "?br>");
}
alert ("Selamat Belajar Struktur Data");
alert ("Semoga Memperoleh Ilmu yang Bermanfaat");
//-->
?/script>
?/body>
?/html>
ARRAY (2)
?html>
?head>
?title>Parameter Array?/title>
?body>
?script language = "JavaScript">
?!--
var tempat = []
var data = prompt("Masukan Jumlah Maksimum Array: ");
for (i=0; i?=data; i++)
{
tempat[i] = prompt("Masukan Bilangan: ");
}
for (j=0; j?=data; j++)
{
document.write("Elemen Array("+j+") = "+tempat[j]+"?br>");
}
//-->
?/script>
?/body>
?/html>
DERET FIBONACCI
?html>
?head>
?script>
?!--
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>
?/head>
?body>
?/body>
?/html>
13 Juli 2009
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar