QBasic Programming

WAP to input any number and check whether the given no. is palindrome or not

CLS
INPUT "ENTER ANY NUMBER"; N
A = N
S = 0
WHILE N < > 0
R = N MOD 10
S = S * 10 + R
N = N \ 10
WEND
IF A = S THEN
PRINT A; "IS PALINDROME"
ELSE
PRINT A; "IS NOT PALINDROME"
END IF
END

USING SUB PROCEDURE
DECLARE SUB PALIN (N)
CLS
INPUT "ENTER ANY NUMBER"; N
CALL PALIN (N)
END
SUB PALIN (N)
A = N
S = 0
WHILE N < > 0
R = N MOD 10
S = S * 10 + R
N = N \ 10
WEND
IF A = S THEN
PRINT A; "IS PALINDROME"
ELSE
PRINT A; "IS NOT PALINDROME"
END IF
END SUB

USING FUNCTION PROCEDURE

DECLARE FUNCTION PALIN (N)
CLS
INPUT "ENTER ANY NUMBER"; N
P = PALIN ((N))
IF P = N THEN
PRINT N; "IS PALINDROME"
ELSE
PRINT N; "IS NOT PALINDROME"
END IF
END

FUNCTION PALIN (N)
S = 0
WHILE N < > 0
R = N MOD 10
S = S * 10 + R
N = N \ 10
WEND
PALIN = S
END FUNCTION

WAP TO ENTER ANY DIGIT AND DISPLAY ITS REVERSED FORM (Prev Lesson)
(Next Lesson) WAP to display first 20 palindrome numbers
Back to QBasic Programming

No Comments

Post a Reply

Course Curriculum

error: Content is protected !!