Wednesday, October 16, 2019

66. Qbasic program to reverse digit


66.      Write a program using FUNCTION procedure to reverse and display the integer number having more than one digit passed as arguments from the main module. [Hint: 123 is reversed as 321].

DECLARE FUNCTION REV (N)
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT " REVERSED DIGITS="; REV (N)
END
FUNCTION REV (N)
S = 0
WHILE N < > 0
R = N MOD 10
S = S * 10 + R
N = N \ 10
WEND
REV = S
END FUNCTION

1 comment: