Saturday, October 22, 2016

Qbasic Program: Product of Digits



148. WAP to input number and find product of digits.
REM
CLS
INPUT "ENTER ANY NUMBER"; N
P = 1
WHILE N < > 0
R = N MOD 10
P = P * R
N = N \ 10
WEND
PRINT "PRODUCT OF DIGITS"; P
END

USING SUB PROCEDURE

DECLARE SUB PROD (N)
CLS
INPUT "ENTER ANY NUMBER"; N
CALL PROD (N)
END

SUB PROD (N)
P = 1
WHILE N < > 0
R = N MOD 10
P = P * R
N = N \ 10
WEND
PRINT "PRODUCT OF DIGITS"; P
END SUB

USING FUNCTION PROCEDURE

DECLARE FUNCTION PROD (N)
CLS
INPUT "ENTER ANY NUMBER"; N
PR = PROD (N)
PRINT "PRODUCT OF DIGITS"; PR
END

FUNCTION PROD (N)
P = 1
WHILE N < > 0
R = N MOD 10
P = P * R
N = N \ 10
WEND
PROD = P
END FUNCTION

149. WAP to input number and find product of odd digits.
REM
CLS
INPUT "ENTER ANY NUMBER"; N
P = 1
WHILE N < > 0
R = N MOD 10
IF R MOD 2 = 1 THEN P = P * R
N = N \ 10
WEND
PRINT "PRODUCT OF ODD DIGITS"; P
END

USING SUB PROCEDURE

DECLARE SUB PROD (N)
CLS
INPUT "ENTER ANY NUMBER"; N
CALL PROD (N)
END

SUB PROD (N)
P = 1
WHILE N < > 0
R = N MOD 10
IF R MOD 2 = 1 THEN P = P * R
N = N \ 10
WEND
PRINT "PRODUCT OF ODD DIGITS"; P
END SUB

USING FUNCTION PROCEDURE

DECLARE FUNCTION PROD (N)
CLS
INPUT "ENTER ANY NUMBER"; N
PR = PROD (N)
PRINT "PRODUCT OF ODD DIGITS"; PR
END

FUNCTION PROD (N)
P = 1
WHILE N < > 0
R = N MOD 10
IF R MOD 2 = 1 THEN P = P * R
N = N \ 10
WEND
PROD = P
END FUNCTION

150. WAP to input number and find product of even digits.
REM
CLS
INPUT "ENTER ANY NUMBER"; N
P = 1
WHILE N < > 0
R = N MOD 10
IF R MOD 2 = 0 THEN P = P * R
N = N \ 10
WEND
PRINT "PRODUCT OF EVEN DIGITS"; P
END

USING SUB PROCEDURE

DECLARE SUB PROD (N)
CLS
INPUT "ENTER ANY NUMBER"; N
CALL PROD (N)
END

SUB PROD (N)
P = 1
WHILE N < > 0
R = N MOD 10
IF R MOD 2 = 0 THEN P = P * R
N = N \ 10
WEND
PRINT "PRODUCT OF EVEN DIGITS"; P
END SUB

USING FUNCTION PROCEDURE

DECLARE FUNCTION PROD (N)
CLS
INPUT "ENTER ANY NUMBER"; N
PR = PROD (N)
PRINT "PRODUCT OF EVEN DIGITS"; PR
END

FUNCTION PROD (N)
P = 1
WHILE N < > 0
 R = N MOD 10
IF R MOD 2 = 0 THEN P = P * R
N = N \ 10
WEND
PROD = P
END FUNCTION

151. WAP to enter any 5 numbers and display its product.
CLS
P = 1
FOR I = 1 TO 5
INPUT "ENTER THE NUMBERS"; N(I)
P = P * N(I)
NEXT I
PRINT "PRODUCT OF 5 NUMBERS"; P
END

USING SUB PROCEDURE
DECLARE SUB PRODUCT (N( ))
CLS
FOR I = 1 TO 5
INPUT "ENTER THE NUMBERS"; N(I)
NEXT I
CALL PRODUCT (N( ))
END


SUB PRODUCT (N())
P = 1
FOR I = 1 TO 5
P = P * N(I)
NEXT I
PRINT "PRODUCT OF 5 NUMBERS"; P
END SUB


USING FUNCTION PROCEDURE
DECLARE FUNCTION PRODUCT (N( ))
CLS
FOR I = 1 TO 5
INPUT "ENTER THE NUMBERS"; N(I)
NEXT I
PRINT "PRODUCT OF 5 NUMBERS"; PRODUCT (N( ))
END


FUNCTION PRODUCT (N())
FOR I = 1 TO 5
P = P * N(I)
NEXT I
PRODUCT = P
END FUNCTION

No comments:

Post a Comment