# QBasic Programming

## WAP to convert decimal number to hexadecimal number

CLS
INPUT "ENTER DECIMAL NUMBER"; D
WHILE D <> 0
R = D MOD 16
IF R < 10 THEN
S\$ = STR\$(R) + S\$
ELSE
S\$ = CHR\$(R + 55) + S\$
END IF
D = D \ 16
WEND
PRINT "HEXADECIMAL EQUIVALENT VALUE="; S\$
END
USING SUB PROCEDURE
DECLARE SUB CONV(D)
CLS
INPUT "ENTER DECIMAL NUMBER"; D
CALL CONV (D)
END
SUB CONV(D)
WHILE D <> 0
R = D MOD 16
IF R = 10 THEN
S\$ = "A"
ELSEIF R = 11 THEN
S\$ = "B"
ELSEIF R = 12 THEN
S\$ = "C"
ELSEIF R = 13 THEN
S\$ = "D"
ELSEIF R = 14 THEN
S\$ = "E"
ELSEIF R = 15 THEN
S\$ = "F"
ELSE
S\$ = STR\$(R) + S\$
END IF
D = D \ 16
WEND
PRINT "HEXADECIMAL EQUIVALENT VALUE="; S\$
END SUB

USING FUNCTION PROCEDURE
DECLARE FUNCTION CONV\$ (D)
CLS
INPUT "ENTER DECIMAL NUMBER"; D
PRINT "HEXADECIMAL EQUIVALENT VALUE=";  CONV\$ (D)
END
FUNCTION CONV\$(D)
WHILE D < > 0
R = D MOD 16
IF R = 10 THEN
S\$ = "A"
ELSEIF R = 11 THEN
S\$ = "B"
ELSEIF R = 12 THEN
S\$ = "C"
ELSEIF R = 13 THEN
S\$ = "D"
ELSEIF R = 14 THEN
S\$ = "E"
ELSEIF R = 15 THEN
S\$ = "F"
ELSE
S\$ = STR\$(R) + S\$
END IF
D = D \ 16
WEND
CONV\$ = S\$
END FUNCTION