ARRAY in QBASIC

array in qbasic
Greatest among 5 numbers using Array

CLS

DIM num(4)

PRINT "Enter any any 5 numbers"

FOR j = 0 TO 4

INPUT num(j)

NEXT j

lrg = num(0)

FOR j = 0 TO 4

IF lrg > num(j) THEN

lrg = num(j)

END IF

NEXT j

PRINT "largest number is="; lrg

END


Input Name and Marks and Display using Array

CLS
DIM n$(5)
DIM m(5)
PRINT "Enter Name and Marks of any 5 students"
FOR i = 1 TO 5
PRINT i
INPUT "Enter Name: "; n$(i)
INPUT "Enter Marks:"; m(i)
NEXT i
PRINT
PRINT
PRINT
PRINT "MARKS OF STUDENTS"
PRINT "NAME", "MARKS", "RESULT"
FOR i = 1 TO 5
IF m(i) >= 40 THEN
r$ = "PASSED"
ELSE
r$ = "FAILED"
END IF
PRINT n$(i), m(i), r$
NEXT i
END


Display Name and Roll using READ DATA

DIM n$(6), roll(6)
CLS
FOR i = 0 TO 6
READ n$(i), roll(i)
NEXT i
FOR i = 0 TO 6
PRINT n$(i), roll(i)
NEXT i
DATA Ganesh,2,Adit,5,Dilip,3,Shailesh,8,Lal,9,Bishal,10,laxman,11
END


sort name in ascending order

CLS
REM*SORTING OF STRING*
PRINT "ENTER NO OF ELEMENTS"
INPUT N
DIM A$(N)
PRINT "ENTER "; N; "NAMES"
FOR I = 1 TO N
INPUT A$(I)
NEXT I
FOR I = 1 TO N – 1
FOR J = 1 TO N – I
IF A$(J) > A$(J + 1) THEN
SWAP A$(J), A$(J + 1)
END IF
NEXT J
NEXT I
PRINT "AFTER SORTING"
FOR I = 1 TO N
PRINT A$(I)
NEXT I
END


matrix addition

CLS
REM*ADDITION OF MATRIX*
INPUT "ENTER ROW"; R
INPUT "ENTER COLUMN"; C
DIM M1(R, C), M2(R, C)
PRINT "ENTER MATRIX M1"
FOR I = 1 TO R
FOR J = 1 TO C
INPUT M1(I, J)
NEXT J
NEXT I
PRINT "ENTER MATRIX M2"
FOR I = 1 TO R
FOR J = 1 TO C
INPUT M2(I, J)
NEXT J
NEXT I
FOR I = 1 TO R
FOR J = 1 TO C
M3(I, J) = M1(I, J) + M2(I, J)
NEXT J
NEXT I
PRINT "ADDTION OF MATRIX"
FOR I = 1 TO C
FOR J = 1 TO R
PRINT M3(I, J);
NEXT J
PRINT
NEXT I
END


Leave a Reply

Your email address will not be published. Required fields are marked *

Enter Captcha Here : *

Reload Image