Wednesday 30 October 2019

Qbasic to find sum of digits using Sub

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 SUM

No comments:

Post a Comment