Wednesday, October 16, 2019

3. Qbasic Program to calculate the sum, product, average and difference of two numbers.

3.      Using FUNCTION, write a program to calculate the sum, product, average and difference of two numbers.

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
PRINT “SUM OF TWO NUMBERS”; SUM (A, B)
PRINT “DIFFERENCE OF TWO NUMBERS”; DIFF (A, B)
PRINT “PRODUCT OF TWO NUMBERS”; PROD (A, B)
PRINT “AVERAGE OF TWO NUMBERS”; AVERAGE (A, B)
END

FUNCTION SUM (A, B)
SUM = A + B
END FUNCTION

FUNCTION DIFF (A, B)
DIFF = A - B
END FUNCTION

FUNCTION PROD (A, B)
PROD = A * B
END FUNCTION

FUNCTION AVERAGE (A, B)
AVERAGE = (A + B) / 2
END FUNCTION

1 comment:

  1. very helpful, keep up the good work hahahahahaha

    ReplyDelete