QBasic Programming

WAP to input number and find sum of digits

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

WAP to enter any 20 numbers and display the greatest and smallest one using array (Prev Lesson)
(Next Lesson) WAP to input number and find sum of odd digits
Back to QBasic Programming

No Comments

Post a Reply

Course Curriculum

error: Content is protected !!