QBASIC program to check whether the input digit is palindrome or not
CLS
INPUT "Enter any
digit:"; d
n = d
WHILE d > 0
r = d MOD 10
s = s * 10 + r
d = INT(d / 10)
WEND
IF n = s THEN
PRINT n; "is palindrome
digit"
ELSE
PRINT n; "is not palindrome
digit"
END IF
END
Using SUB procedure (SUB….END
SUB)
DECLARE SUB pal (d)
CLS
INPUT "Enter any
digit:"; d
CALL pal(d)
END
SUB pal (d)
n = d
WHILE d > 0
r = d MOD 10
s = s * 10 + r
d = INT(d / 10)
WEND
IF n = s THEN
PRINT n; "is palindrome
digit"
ELSE
PRINT n; "is not palindrome
digit"
END IF
END SUB
Using FUNCTION procedure
(FUNCTION…END FUNCTION)
DECLARE FUNCTION pal$ (d)
CLS
INPUT "Enter any
digit:"; d
PRINT d; pal$(d)
END
FUNCTION pal$ (d)
n = d
WHILE d > 0
r = d MOD 10
s = s * 10 + r
d = INT(d / 10)
WEND
IF n = s THEN
pal$ = "is palindrome
digit"
ELSE
pal$ = "is not palindrome
digit"
END IF
END FUNCTION
Output:
No comments:
Post a Comment