Jumat, 21 Oktober 2011

looping (perulangan)

coding :
<html>
<head><title>looping</title></head>
<body>
<script type="text/javascript">
var i , b, j ;
for(i=0;i<=4;i++)
{
for(b=0;b<=1*i;b++)
{
document.write("*");
}
document.write("<br>");
}
for(i=3;i>=0;i--)
{
for(b=0;b<=1*i;b++)
{
document.write("*");
}
document.write("<br>");
}
</script>
</body>
</html>



coding :

<html>
<head><title>looping2</title>
</head>
<body>
<script type="text/javascript">
var x = new Array();
var input = 8;
for(i= 1;i<= 8;i++)
{
x[i]=new Array();
for(j=1;j<=i;j++)
{
if(j==1 || j==i)
{
x[i][j]=1;
}
else
{
x[i][j] = x[i-1][j-1] + x[i-1][j];
}
}
}
for(i= 1;i<= 8;i++)
{
for(j=1;j<=i;j++)
{
document.write(x[i][j]+" ");
}
document.write("<br>")
}
</script>
</body>
</html>

coding :
<html>
<head><title>looping3</title>
</head>
<body>
<script type="text/javascript">
jumlah = 9;
i = 0;
j = 0;
n = jumlah - 1;

while (i < jumlah)
{
y = i + 1;
while (j <= i)
{
document.write(y + " ");
y = y + n;
n--;
j++;
}
n = jumlah - 1;
j = 0;
document.write("<br>");
i++;
}
</script>
</body>
</html>

coding :
<html>
<head>
<title>looping4</title>
</head>

<body>
<script type="text/javascript">
var x = 5;
var i = 1;
var y;
while( i <= x+1 )
{
for( y=1;y <= x + 1 ;y++)
{
if(( i == y ) || (y == x + 2 - i )){
document.write("X");
}
else
{
document.write("=");
}
}
document.write("<br/>");
i++;
}
</script>
</body>
</html>



Tidak ada komentar:

Posting Komentar