Thursday 10 September 2020

5. Write a QBasic Program to Enter any two numbers and display its sum, difference, product and average.

5. Enter any two numbers and display its sum, difference, product and average.


REM PROGRAM TO DISPLAY SUM, DIFFERENCE, PRODUCT AND AVERAGE  OF TWO NUMBERS

CLS

INPUT “ENTER FIRST NUMBER”; A

INPUT “ENTER SECOND NUMBER”; B

S = A + B

D = A – B

P = A * B

AV = (A + B) / 2

PRINT “SUM OF TWO NUMBERS”; S

PRINT “DIFFERENCE OF TWO NUMBERS”; D

PRINT “PRODUCT OF TWO NUMBERS”; P

PRINT “AVERAGE OF TWO NUMBERS”; AV

END

 

USING SUB PROCEDURE

 

DECLARE SUB SUM (A, B)

DECLARE SUB DIFF (A, B)

DECLARE SUB PROD (A, B)

DECLARE SUB AVERAGE (A, B)

CLS

INPUT “ENTER FIRST NUMBER”; A

INPUT “ENTER SECOND NUMBER”; B

CALL SUM(A, B)

CALL DIFF(A, B)

CALL PROD(A, B)

CALL AVERAGE(A, B)

END

 

SUB SUM (A, B)

S = A + B

PRINT “SUM OF TWO NUMBERS”; S

END SUB

SUB DIFF (A, B)

D = A - B

PRINT “DIFFERENCE OF TWO NUMBERS”; D

END SUB

SUB PROD (A, B)

P = A * B

PRINT “PRODUCT OF TWO NUMBERS”; P

END SUB

 

SUB AVERAGE (A, B)

AV = (A + B) / 2

PRINT “AVERAGE OF TWO NUMBERS”; AV

END SUB

 

USING FUNCTION PROCEDURE

 

DECLARE FUNCTION SUM (A, B)

DECLARE FUNCTION DIFF (A, B)

DECLARE FUNCTION PROD (A, B)

DECLARE FUNCTION AVERAGE (A, B)

CLS

INPUT “ENTER FIRST NUMBER”; A

INPUT “ENTER SECOND NUMBER”; B

S = SUM(A, B)

D = DIFF (A, B)

P = PROD(A, B)

AV = AVERAGE(A, B)

PRINT “SUM OF TWO NUMBERS”; S

PRINT “DIFFERENCE OF TWO NUMBERS”; D

PRINT “PRODUCT OF TWO NUMBERS”; P

PRINT “AVERAGE OF TWO NUMBERS”; AV

END

 

FUNCTION SUM (A, B)

SU = A + B

SUM = SU

END FUNCTION

 

FUNCTION DIFF (A, B)

D = A - B

DIFF = D

END FUNCTION

 

FUNCTION PROD (A, B)

P = A * B

PROD = P

END FUNCTION

 

FUNCTION AVERAGE (A, B)

AVGR = (A + B) / 2

AVERAGE = AVGR

END FUNCTION

No comments:

Post a Comment

MCQ Question Bank Microsoft PowerPoint