Quick Basic in Application

Print out Prime Numbers

Posted by: programmervb on: March 6, 2009

‘ look at a series of numbers and print out the prime numbers
‘ prime numbers are divisible only by unity or themselves
‘ this is BCX basic, a modern successor to Qbasic

Dim A    ‘ defaults to integer

For A = 1 To 100
If IsPrime(A) Then Print A;
Next

Pause   ‘ make console wait

Function IsPrime(Num)
Local X
‘ make exeptions for unity and 2
If Num = 1 Then Function = True
If Num = 2 Then Function = True
‘ leave on even numbers
If Mod(Num, 2) = 0 Then Exit Function
For X = 3 To Num – 1 Step 2
If Mod(Num, X) = 0 Then Exit Function
Next X
Function = TRUE  ‘ return true if it’s a Prime Number
End Function

Tags:

Qbasic Character Counter

Posted by: programmervb on: March 6, 2009

DECLARE SUB GetWords (st$, wds%)

st$ = “Hello my name is John Doe”
IF RIGHT$(st$, 1) <> ” ” THEN st$ = st$ + ” “
FOR k% = 1 TO LEN(st$)
IF MID$(st$, k%, 1) = ” ” THEN words% = words% + 1
characters% = characters% + 1
NEXT
PRINT “total characters=”; characters%
PRINT “total words=”; words%

xst$ = “Hello my name is John Doe”
GetWords xst$, words%
PRINT “words= “; words%

SUB GetWords (st$, wds%)
IF RIGHT$(st$, 1) <> ” ” THEN st$ = st$ + ” “
FOR k% = 1 TO LEN(st$)
IF MID$(st$, k%, 1) = ” ” THEN words% = words% + 1
characters% = characters% + 1
NEXT
‘print “total characters=”;characters%
‘print “total words=”;words%
wds% = words%
END SUB

Tags:

Multiply Matrix

Posted by: programmervb on: August 16, 2008

‘Multiply Matrix

1040 ‘multiply matrix module
1050 CLS:INPUT “BANYAK BARIS,BANYAK KOLOM MATRIX 1″;P,Q
1060 INPUT “BANYAK BARIS,BANYAK KOLOM MATRIX 2″;R,S
1070 IF Q<>R THEN PRINT “TIDAK TERDEFINISI”:STOP:GOTO 1050
1080 DIM A(P,Q),B(R,S),C(P,S)
1090 PRINT:PRINT”ELEMEN MATRIX 1:”:PRINT
1100 FOR I=1 TO P:FOR J=1 TO A:PRINT”BARIS”;I;”KOLOM”;J;:INPUT A(I,J):NEXT J,I
1110 PRINT:PRINT”ELEMEN MATIRX 2:”:PRINT
1120 FOR I=1 TO R:FOR J=1 TO S:PRINT”BARIS”;I;”KOLOM”;K;:INPUT B(I,J):NEXT J,I
1130 FOR I=1 TO P
1140 FOR J=1 TO S
1150 C(I,J)=0
1160 FOR K=1 TO Q
1170 C(I,J)=C(I,J)+A(I,K)*B(K,J)
1180 NEXT K
1190 NEXT J
1200 NEXT I
1210 ‘SELESAI CETAK
1220 CLS:PRINT”MATRIX HASIL KALI:”:PRINT
1230 FOR I=1 TO P
1240 FOR J=1 TO S:PRINT USING “####.#”;C(I,J);:NEXT J
1250 PRINT
1260 NEXT I
1270 END