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

How to Write a QBASIC Program to enter any three numbers and display the smallest number

How to Write a QBASIC Program to enter any three numbers and display the smallest number


How to Write a QBASIC Program to enter any three numbers and display the smallest number


Introduction:


Are you looking to write a program that can take three numbers as inputs and display the smallest number among three numbers? If so, you've come to the right place! In this article, we'll teach you how to write a QBASIC program that does just that. QBASIC is a high-level programming language that is easy to learn and use. It's perfect for beginners who want to start their programming journey. So, let's get started with writing a QBASIC Program to enter any three numbers and display the smallest number.

How to Write a QBASIC Program that Inputs Three Numbers and Displays the Smallest Number Among Three Numbers


Step 1: Input the Three Numbers


We need to input the three numbers from the user. We can use the INPUT statement in QBASIC to do this. Here's how we can input the three numbers:

INPUT "Enter the first number: ", num1 INPUT "Enter the second number: ", num2 INPUT "Enter the third number: ", num3



Step 2: Find the Smallest Number

Now that we've input the three numbers, we need to find the smallest number among three numbers. We can do this by using an IF statement in QBASIC. Here's how we can find the smallest number:


IF num1 < num2 AND num1 < num3 THEN 
smallest = num1 
ELSEIF num2 < num1 AND num2 < num3 THEN 
smallest = num2 
ELSE 
smallest = num3 
END IF


Step 3: Display the Smallest Number


Finally, we need to display the smallest number among the three numbers. We can use the PRINT statement in QBASIC to do this. Here's how we can display the smallest number:


PRINT "The smallest number among three numbers is: "; smallest

 Example: QBASIC Program to enter any three numbers and display the smallest number by using SUB procedure (SUB..END SUB)

DECLARE SUB sm ()

CLS

CALL sm

END

 

SUB sm

INPUT "Enter first number:"; a

INPUT "Enter second number:"; b

INPUT "Enter third number:"; c

IF a < b AND a < c THEN

s = a

ELSEIF b < c THEN

s = b

ELSE

s = c

END IF

PRINT "Smallest no:"; s

END SUB

 

Example: QBASIC Program to enter any three numbers and display the smallest number by using FUNCTION procedure (FUNCTION…END FUNCTION)

DECLARE FUNCTION sm (a, b, c)

CLS

INPUT "Enter first number:"; a

INPUT "Enter second number:"; b

INPUT "Enter third number:"; c

small = sm(a, b, c)

PRINT "Smallest no="; small

END

 

FUNCTION sm (a, b, c)

IF a < b AND a < c THEN

s = a

ELSEIF b < c THEN

s = b

ELSE

s = c

END IF

sm = s

END FUNCTION

 

Output




FAQs:


Q: What if the user inputs negative numbers? 
A: The program will still be able to determine the smallest number among the three input numbers, regardless of whether they are positive or negative.

Q: Can this program be modified to display the largest number instead of the smallest number? 
A: Yes, by modifying the IF statement, we can find the largest number instead of the smallest number.

Q: Is QBASIC a commonly used programming language? 
A: QBASIC is not as widely used as some other programming languages, but it is still used in some applications and can be a useful language for beginners to learn.

Conclusion:


In conclusion, writing a QBASIC Program to enter any three numbers and display the smallest number is a great exercise for beginners in programming. By following the steps outlined in this article, anyone can write a simple program to accomplish this task. QBASIC is a great language to learn for those who are just starting out with programming, as it is easy to learn and use. With practice and continued learning, one can build upon this simple program to create more complex programs in the future.



No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages