QBASIC PROGRAM TO FIND AREA OF A RECTANGLE USING SUB AND FUNCTION
Solution:
To find the area of a rectangle using QBasic we will use the formula: Area = Length(L) * breadth(B) and store the output in variable A. We will use the PRINT command to print out the result.
Area of a rectangle
REM PROGRAM TO DISPLAY AREA OF RECTANGLE
CLS
INPUT “ENTER LENGTH”; L
INPUT “ENTER BREADTH”; B
A = L * B
PRINT “AREA OF RECTANGLE ”; A
END
Area of a rectangle using Sub Procedure
DECLARE SUB AREA (L, B)
CLS
INPUT “ENTER LENGTH”; L
INPUT “ENTER BREADTH”; B
CALL AREA(L, B)
END
SUB AREA (L, B)
A = L * B
PRINT “AREA OF RECTANGLE ”; A
END SUB
Area of a rectangle using Functional Procedure
DECLARE FUNCTION AREA (L, B)
CLS
INPUT “ENTER LENGTH”; L
INPUT “ENTER BREADTH”; B
AR = AREA(L, B)
PRINT “AREA OF RECTANGLE ”; AR
END
FUNCTION AREA (L, B)
A = L * B
AREA = A
END FUNCTION