QBASIC Program To Print The Sum Of Digits Of A Number

 QBASIC Program To Print The Sum Of Digits Of A Number

QBASIC Program To Print The Sum Of Digits Of A Number



QBASIC Program To Print The Sum Of Digits Of A Number

CLS
INPUT" Enter a number"; N
WHILE N<>0
R=N MOD 10
S=S+R
N=N\10
WEND
PRINT " The sum of digits is ";S
END

QBASIC Program To Print The Sum Of Digits Of A Number Using SUB Procedure

DECLARE SUB SUM(N)
CLS
INPUT" Enter a number"; N
CALL SUM(N)
END
SUB SUM(N)
WHILE N<>0
R=N MOD 10
S=S+R
N=N\10
WEND
PRINT " The sum of digits  is ";S
END SUB


QBASIC Program To Print The Sum Of Digits Of A Number Using FUNCTION Procedure

DECLARE FUNCTION SUM(N)
CLS
INPUT" Enter a number"; N
PRINT"The sum of digits is"; SUM(N)
END
FUNCTION SUM(N)
WHILE N<>0
R=N MOD 10
S=S+R
N=N\10
WEND
SUM =S
END FUNCTION


Comments