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

Thursday, December 1, 2022

QBASIC program to input any three strings and display the longest string among them

 QBASIC program to input any three strings and display the longest string among them


CLS

INPUT "Enter first string:"; a$

INPUT "Enter second string:"; b$

INPUT "Enter third string:"; c$

x = LEN(a$)

y = LEN(b$)

z = LEN(c$)

IF x > y AND x > z THEN

l$ = a$

ELSEIF y > z THEN

l$ = b$

ELSE

l$ = c$

END IF

PRINT "Longest string="; l$

END

 

Using SUB procedure (SUB…END SUB)

DECLARE SUB longest ()

CLS

CALL longest

END

 

SUB longest

INPUT "Enter first string:"; a$

INPUT "Enter second string:"; b$

INPUT "Enter third string:"; c$

x = LEN(a$)

y = LEN(b$)

z = LEN(c$)

IF x > y AND x > z THEN

l$ = a$

ELSEIF y > z THEN

l$ = b$

ELSE

l$ = c$

END IF

PRINT "Longest string="; l$

END SUB

 

Using FUNCTION procedure (FUNCTION…END FUNCTION)

DECLARE FUNCTION longest$ (a$, b$, c$)

CLS

INPUT "Enter first string"; a$

INPUT "enter second string:"; b$

INPUT "Enter third string:"; c$

lo$ = longest$(a$, b$, c$)

PRINT "Longest string="; lo$

END

 

FUNCTION longest$ (a$, b$, c$)

x = LEN(a$)

y = LEN(b$)

z = LEN(c$)

IF x > y AND x > z THEN

l$ = a$

ELSEIF y > z THEN

l$ = b$

ELSE

l$ = c$

END IF

longest$ = l$

END FUNCTION

 

Output:




No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages