To check a number is palindrome or not. (Qbasic Code)

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 palindrome (N)
CLS
INPUT "Enter any number"; N
CALL palindrome (N)
END

SUB palindrome (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 palindrome(n)
CLS
INPUT "Enter any number"; n
m = n
IF m = palindrome(n) THEN
    PRINT m; "is palindrome number";
ELSE
    PRINT m; "is not palindrome number";
END IF

FUNCTION palindrome (n)
WHILE n <> 0
    r = n MOD 10
    s = s * 10 + r
    n = n \ 10
WEND
palindrome = s
END FUNCTION

Share :

Twitter
Back To Top

facebook main

counter

Powered by Blogger.