QBasic Programming

WAP to input number and find sum of cube of odd digits

CLS
INPUT "ENTER ANY NUMBER"; N
S = 0
WHILE N < > 0
R = N MOD 10
IF R MOD 2 = 1 THEN S = S + R ^ 3
N = N \ 10
WEND
PRINT "SUM OF CUBE OF ODD DIGITS"; S
END
USING SUB PROCEDURE
DECLARE SUB SUMODD (N)
CLS
INPUT "ENTER ANY NUMBER"; N
CALL SUMODD (N)
END
SUB SUMODD (N)
S = 0
WHILE N < > 0
R = N MOD 10
IF R MOD 2 = 1 THEN S = S + R ^ 3
N = N \ 10
WEND
PRINT "SUM OF CUBE OF ODD DIGITS"; S
END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION SUMODD (N)
CLS
INPUT "ENTER ANY NUMBER"; N
SU = SUMODD (N)
PRINT "SUM OF CUBE OF ODD DIGITS"; SU
END
FUNCTION SUMODD (N)
S = 0
WHILE N < > 0
R = N MOD 10
IF R MOD 2 = 1 THEN S = S + R ^ 3
N = N \ 10
WEND
SUMODD = S : END FUNCTION

WAP to input number and find sum of cube of digits (Prev Lesson)
(Next Lesson) WAP to input number and find sum of cube of even digits
Back to QBasic Programming

No Comments

Post a Reply

Course Curriculum

error: Content is protected !!