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 shortest string among them

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



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


Introduction:

QBASIC is a simple and easy-to-use programming language that can be used to develop a wide range of applications. In this blog article, we will discuss how to write a QBASIC program to input any three strings and display the shortest string among them.

Body:

To write a QBASIC program that finds the shortest string among three strings, we can follow the following steps:
  1. Prompt the user to input three strings using the INPUT statement.
  2. Compare the length of the strings using the LEN function.
  3. Use a simple IF statement to compare the length of the strings and determine which string is the shortest.
  4. Display the shortest string to the user using the PRINT statement.
The program can be written as follows:


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 "Smallest string="; l$
END



By using SUB procedure (SUB…END SUB)

DECLARE SUB small ()
CLS
CALL small
END



SUB small
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 "Smallest string="; l$
END SUB



By 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

Explanation:

This program prompts the user to input three strings and then compares the length of each string using the LEN function. It then uses an IF statement to determine which string is the shortest and displays the shortest string to the user using the PRINT statement.


Output:




Conclusion:

In conclusion, writing a QBASIC program to input any three strings and display the shortest string among them is a simple and straightforward task. By following the steps outlined in this article, we can easily write a program that takes input from the user and determines which string is the shortest. QBASIC is an excellent language for beginners to learn programming concepts, and this program is a great way to practice programming skills in QBASIC. With a little bit of practice, anyone can create a program that performs this task and many other useful tasks using QBASIC.

You can also Read:


No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages