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