input any string and reverse it, palindrome

221. WAP to input any string and reverse it.


CLS
INPUT "ENTER ANY STRING"; S$

FOR I = LEN(S$) TO 1 STEP -1
B$ = MID$(S$, I, 1)
W$ = W$ + B$
NEXT I
PRINT "REVERSED STRING IS "; W$
END

USING SUB PROCEDURE

DECLARE SUB REV (S$)
CLS
INPUT "ENTER ANY STRING"; S$
CALL REV(S$)
END

SUB REV (S$)
FOR I = LEN(S$) TO 1 STEP -1
B$ = MID$(S$, I, 1)
W$ = W$ + B$
NEXT I
PRINT "REVERSED STRING IS "; W$
END SUB

USING FUNCTION PROCEDURE

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

222.  WAP to input any string and check whether the given string is palindrome or not.

CLS
INPUT "ENTER ANY STRING"; S$
FOR I = LEN(S$) TO 1 STEP -1
B$ = MID$(S$, I, 1)
W$ = W$ + B$
NEXT I
IF S$ = W$ THEN
PRINT  S$; “IS PALINDROME”
ELSE
PRINT S$; “IS NOT PALINDROME”
END IF
END

USING SUB PROCEDURE

DECLARE SUB REV (S$)
CLS
INPUT "ENTER ANY STRING"; S$
CALL REV(S$)
END

SUB REV (S$)
FOR I = LEN(S$) TO 1 STEP -1
B$ = MID$(S$, I, 1)
W$ = W$ + B$
NEXT I
IF S$ = W$ THEN
PRINT  S$; “IS PALINDROME”
ELSE
PRINT S$; “IS NOT PALINDROME”
END IF
END SUB

USING FUNCTION PROCEDURE

DECLARE FUNCTION REV$ (S$)
CLS
INPUT "ENTER ANY STRING"; S$
C$ = REV$(S$)
IF S$ = C$ THEN
PRINT  S$; “IS PALINDROME”
ELSE
PRINT S$; “IS NOT PALINDROME”
END IF
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

Comments

ARJUN PAUDEL said…
reverse the word.
eg:- old is gold.
the reverse is := gold is old.
Unknown said…
plz can u solve this question...............for my daughter
WAP TO INPUT A YEAR AND DETERMINE WHETHER ITS A LEAP YEAR OR NOT
Unknown said…
This comment has been removed by the author.
Anonymous said…
That doesn't work like thatπŸ˜‚πŸ˜‚πŸ˜‚
Unknown said…
Write a q basic program to print (program,rogra,ogr,g) in triangle form
Unknown said…
Write a program to enter a string and print all the palindrome words present in it.
Unknown said…
Thank you
Please can you solve this problem
Write a QBASIC program to print following string pattern:
VOSTRO
VOSTR
VOST
VOS
VO
V

Unknown said…
Have you any logic to print a sentence in its reverse order... I am boy..boy am I

Popular posts from this blog

PROGRAM TO FIND SQUARE, CUBE, SQUARE ROOT AND CUBE ROOT OF GIVEN NUMBER

PALINDROME AND ARMSTRONG PROGRAMS

PROGRAM TO DISPLAY SUM, PRODUCT, DIFFERENCE AND PRODUCT OF TWO / THREE NUMBERS