QBASIC PROGRAM TO CHECK WHETHER A STRING IS PALINDROME OR NOT
INPUT : MAM
OUTPUT : MAM IS PALINDROME
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
DECLARE SUB PALINDROME(S$)
CLS
INPUT ENTER ANY STRING; S$
CALL PALINDROME(S$)
END
SUB PALINDROME(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
0 Comments