QBASIC program to display the input digit in reverse order
CLS
INPUT "Enter any
digit:"; d
n = d
WHILE d > 0
r = d MOD 10
s = s * 10 + r
d = INT(d / 10)
WEND
PRINT "Reverse digit
of"; n; "is"; s
END
By using SUB procedure (SUB..END
SUB)
DECLARE SUB rev (d)
CLS
INPUT "Enter any
digit:"; d
CALL rev(d)
END
SUB rev (d)
n = d
WHILE d > 0
r = d MOD 10
s = s * 10 + r
d = INT(d / 10)
WEND
PRINT "Reverse of"; n;
"is"; s
END SUB
By using FUNCTION procedure
(FUNCTION…END FUNCTION)
DECLARE FUNCTION rev (d)
CLS
INPUT "Enter any
digit:"; d
PRINT "Reverse digit
of"; d; "is"; rev(d)
END
FUNCTION rev (d)
WHILE d <> 0
r = d MOD 10
s = s * 10 + r
d = d \ 10
WEND
rev = s
END FUNCTION
Output:
No comments:
Post a Comment