You are on page 1of 2

C1.

Norma Devi Kurniasari


214210447
Mencetak deret 0,1,3,6,10,15,21,28,... infinite loop.

a=0
b=0

<script language="vbscript">

While a
>0
Cetak a

a=0
b=1
do
document.write a & ", "
a=a+b
b=b+1
loop while a > 0

a = a+ b
b=b+1

</script>

C3.

3 (tiga) program untuk tujuan yang sama, yaitu


mencetak deret bilangan berikut:
100, 95, 90, 85, .......... , -140, -145, -150
memakai angka-angka 100, -150, dan -5. Jangan
memakai angka-angka lainnya.
a. <script language="vbscript">

a.

For i=100 to -150


step -5
Write i

for i=100 to -150 step -5


document.write i & " , "
next
</script>
b. <script language="vbscript">
a=100
do
document.write a & ", "
a=a-5
loop until a<-150
</script>
c. <script language="vbscript">
a=100
do while a>=-150
document.write a & ", "
a=a-5
loop
</script>

b.
no

a=
100
a=a5 a <-

Write
a

c.

150

yes
-

Until

a=
100
While a>=150
Write a
A=a-5

Norma Devi Kurniasari


214210447
C5. Write a flowchart that shows the sum of 1 to n for every n
from 1 to 50. That is, the flowchart prints 1, 3 (the sum of 1
and 2), 6 (the sum of 1, 2, and 3), and so on.

C5.
a=1
b=1

<script language="vbscript">
a=1
b=1
do while a<=50
document.write b & " , "
a=a+1
b=b+a
loop
</script>

C6. Menghitung nilai deret berikut:


2 + 4 + 8 + 16 + ....... + 8192. Perhatikan bahwa
8192=213

While a <=
50
Cetak b
a = a+ 1
b=b+a

C6.

<script language="vbscript">
for i =1 to 13
c=c+2^i
document.write 2^i & " + "
next
document.write "<br>" & "Nilai deret = "
&c
</script>

C7. Menghitung nilai deret berikut:


1001 - 1 + 2 - 4 + 8 - 16 ..... 2N
N adalah data input yang harus bulat positif.

C7.

<script language="vbscript">
a=cint(inputbox("Masukkan bilangan"))
b=1001
for i=0 to a
b=b+(-1^(i+1))*(2^i)
next
document.write "Nilai deret = " & b
</script>
N
Y

You might also like