9 Contoh program Q basic

Standar

Macam-macam contoh program Q Basic :

Program 1 :

10 REM HITUNGAN

20 LET A = 90

30 LET B = 40

40 C = A * B

50 PRINT C

60 END

 

Output :

3600

 

Program 2 :

10 REM INPUT

20 CLS

30 INPUT “MASUKAN A = “; A

40 INPUT “MASUKAN B = “; B

50 C = A + B

60 PRINT C

70 END

 

Output :

MASUKAN A = 50

MASUKAN B = 70

120

 

Program 3 :

10 REM RELASI

20 CLS

30 INPUT “MASUKAN NILAI = “; NILAI

40 IF NILAI <= 60 THEN

50 PRINT “GAGAL”

60 ELSE

70 PRINT “LULUS”

80 END IF

90 END

 

Output :

JIKA MEMASUKKAN NILAI 50, MAKA OUTPUT :

 

MASUKAN NILAI = 50

GAGAL

 

JIKA MEMASUKKAN NILAI 90, MAKA OUTPUT :

 

MASUKAN NILAI = 90

LULUS

 

Program 4 :

CLS

WHILE i < 3

PRINT “A”

i = i + 1

END

 

Output :

A

A

A

 

Program 5 :

CLS

INPUT “MASUKAN BILANGAN : “; A

INPUT “MASUKAN BILANGAN : “; B

FOR B = 1 TO B

FOR C = 1 TO C

PRINT C;

NEXT C

PRINT

NEXT

END

 

Output :

MASUKAN BILANGAN : -1

MASUKAN BILANGAN : 6

1

1 2

1 2 3

1 2 3 4

1 2 3 4 5

 

Program 6 :

CLS

INPUT “MASUKAN A = “; A

FOR B = A – 1 TO 1 STEP -1

FOR C = 1 TO B

PRINT “*”;

NEXT C

PRINT

NEXT

END

 

Output :

MASUKAN A = 6

* * * * *

* * * *

* * *

* *

*

 

Program 7 :

CLS

FOR A = 1 TO 4

PRINT “KOMPUTER”

NEXT A

END

 

Output :

KOMPUTER

KOMPUTER

KOMPUTER

KOMPUTER

 

Program 8 :

CLS

FOR i = 1 TO 10 STEP 2

PRINT i

NEXT i

END

 

Output :

2

4

6

8

10


Program 9 :

CLS

GO TO 20

10 WRITE “SISTEM INFORMASI”

20 WRITE “SISTEM KOMPUTER”

END

 

Output :

SISTEM KOMPUTER

 

Sumber : Catatan Laboratorium

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s