Computer for SEE and NEB

It is a complete SEE and NEB solution for computer science. It includes Computer Fundamentals, Database (SQL), Programming in C QBASIC, CSS, JavaScript, and PHP for beginners.

Breaking

Post Top Ad

Your Ad Spot

Sunday, November 27, 2022

QBASIC program to check whether input string is palindrome or not.

 QBASIC program to check whether input string is palindrome or not.


CLS

INPUT "Enter string:"; b$

FOR i = LEN(b$) TO 1 STEP -1

p$ = p$ + MID$(b$, i, 1)

NEXT i

PRINT c$

IF b$ = p$ THEN

PRINT "String is Palindrome"

ELSE

PRINT "String is not Palindrome"

END IF

END

DECLARE FUNCTION pal$ (b$)

CLS

INPUT "Ente any string:"; b$

PRINT "String is:"; pal$(b$)

END

 

By using the FUNCTION Procedure (FUNCTION ...END FUNCTION)

FUNCTION pal$ (b$)

FOR x = LEN(b$) TO 1 STEP -1

p$ = p$ + MID$(b$, x, 1)

NEXT x

IF b$ = p$ THEN

m$ = "Palindrome"

ELSE

m$ = "Not palindrome"

END IF

pal$ = m$

END FUNCTION

 

DECLARE SUB pal (b$)

CLS

INPUT "Enter string"; b$

CALL pal(b$)

END

 

By using the SUB Procedure (SUB ... END SUB)

SUB pal (b$)

FOR x = LEN(b$) TO 1 STEP -1

p$ = p$ + MID$(b$, x, 1)

NEXT x

IF b$ = p$ THEN

PRINT "String is Palindrome"

ELSE

PRINT "String is not Palindrome"

END IF

END SUB

 

Output:



No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages