Thursday, October 17, 2019

126. Qbasic Program to get a word from the user and print the word in the reverse order


126.      Write a program using FUNCTION to get a word from the user and print the word in the reverse order.

DECLARE FUNCTION REV$ (S$)
CLS
INPUT "ENTER ANY STRING"; S$
PRINT "REVERSED STRING IS "; REV$(S$)
END

FUNCTION REV$ (S$)
FOR I = LEN(S$) TO 1 STEP -1
B$ = MID$(S$, I, 1)
W$ = W$ + B$
NEXT I
REV$ = W$
END FUNCTION

2 comments: