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 Enter Any Three Numbers and Display the Greatest Number

 QBASIC program to enter any three numbers and display the greatest number


QBASIC program to enter any three numbers and display the greatest number


Introduction

In the world of computer programming, QBASIC has been one of the most popular languages for decades. It is a high-level language that is used to write programs that are easy to read and understand. In this article, we will discuss how to write a QBASIC program to enter any three numbers and display the greatest number.


Getting Started


Before we begin, you need to have a basic understanding of QBASIC. QBASIC is an interpreter language, which means that it runs programs directly from the source code without the need for a compiler. You can download QBASIC from various online sources. Once you have QBASIC installed on your system, you can begin writing your program.


Coding for QBASIC Program to Enter Any Three Numbers and Display the Greatest Number

CLS
INPUT "Enter the first number: ", Num1
INPUT "Enter the second number: ", Num2
INPUT "Enter the third number: ", Num3
IF Num1 > Num2 AND Num1 > Num3 THEN
PRINT "The greatest number is "; Num1
ELSEIF Num2 > Num1 AND Num2 > Num3 THEN
PRINT "The greatest number is "; Num2
ELSE
PRINT "The greatest number is "; Num3
ENDIF
END


Explanation of the Code:

The first line of the code, CLS, clears the screen. The next three lines prompt the user to enter three numbers.


Next, we have an IF statement that checks which of the three numbers is the greatest. The logical operator used here is AND. The condition in the IF statement is true only if both of the conditions separated by the AND operator are true.


The first condition is Num1 > Num2, which checks whether the first number entered is greater than the second number. The second condition is Num1 > Num3, which checks whether the first number entered is greater than the third number. If both of these conditions are true, then the first number entered is the greatest number, and the program displays "The greatest number is" followed by the value of Num1.


The next condition is an ELSEIF statement. If the first condition is false, then the program checks whether the second number is the greatest number. If Num2 is greater than both Num1 and Num3, then the program displays "The greatest number is" followed by the value of Num2.


If both of the above conditions are false, then the program moves to the ELSE statement, where it displays "The greatest number is" followed by the value of Num3.
Finally, the program ends with the END statement.

 

Example: QBASIC program to enter any three numbers and display the greatest number by using SUB procedure (SUB…END SUB)

DECLARE SUB gr ()

CLS

CALL gr

END

 

SUB gr

INPUT "Enter first number:"; a

INPUT "Enter second number:"; b

INPUT "Enter third number:"; c

IF a > c AND a > b THEN

g = a

ELSEIF b > c THEN

g = b

ELSE

g = c

END IF

PRINT "Greatest no:"; g

END SUB

 

Example: QBASIC program to enter any three numbers and display the greatest number by using FUNCTION procedure

DECLARE FUNCTION gr (a, b, c)

CLS

INPUT "Enter first number:"; a

INPUT "Enter second number:"; b

INPUT "Enter third number:"; c

great = gr(a, b, c)

PRINT "Greatest no="; great

END

 

FUNCTION gr (a, b, c)

IF a > c AND a > b THEN

g = a

ELSEIF b > c THEN

g = b

ELSE

g = c

END IF

gr = g

END FUNCTION

 

Output:




Conclusion

In this article, we discussed how to write a QBASIC program to enter any three numbers and display the greatest number. We went through the steps of declaring variables, getting user input, finding the greatest number, and running the program. QBASIC is a powerful language that can be used for a variety of purposes, and we hope this article has helped you in your QBASIC programming journey.

FAQs


1) What is QBASIC? 
Ans: QBASIC is a high-level language used to write programs that are easy to read and understand.


2) Can QBASIC be downloaded from the internet? 
Ans: Yes, QBASIC can be downloaded from various online sources.


3) What is an interpreter language? 
Ans: An interpreter language runs programs directly from the source code without the need for a compiler.


4) Can QBASIC be used for other purposes? 
Ans: Yes, QBASIC is a versatile language that can be used for a variety of purposes.


5) What are some other programming languages similar to QBASIC? 
Ans: Other programming languages similar to QBASIC include Visual Basic, Pascal, and C++.


You may also Read:



No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages