QBasic Programming

WAP to input number and find sum of square 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 ^ 2
N = N \ 10
WEND
PRINT "SUM OF SQUARE 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 ^ 2
N = N \ 10
WEND
PRINT "SUM OF SQUARE 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 SQUARE 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 ^ 2
N = N \ 10
WEND
SUMODD = S : END FUNCTION

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

No Comments

Post a Reply

Course Curriculum

error: Content is protected !!