QBasic Programming

WAP to input number and find sum square of digits

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

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

No Comments

Post a Reply

Course Curriculum

error: Content is protected !!