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 middle number

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


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



Introduction:

QBASIC is a programming language that is popularly used for its simplicity and ease of learning. One of the common tasks in programming is sorting and displaying numbers in ascending or descending order. In this article, we will be discussing how to use QBASIC program to enter any three numbers and display the middle number. 


CLS

INPUT "Enter first number:"; a

INPUT "Enter second number:"; b

INPUT "Enter third number:"; c

IF (a < b AND a > c) OR (a > b AND a < c) THEN

m = a

ELSEIF (b < a AND b > c) OR (b > a AND b < c) THEN

m = b

ELSE

m = c

END IF

PRINT "Middle no:"; m

END

 

By using SUB procedure (SUB..END SUB)

DECLARE SUB middle ()

CLS

CALL middle

END

 

SUB middle

INPUT "Enter first number:"; a

INPUT "Enter second number:"; b

INPUT "Enter third number:"; c

IF (a < b AND a > c) OR (a > b AND a < c) THEN

m = a

ELSEIF (b < a AND b > c) OR (b > a AND b < c) THEN

m = b

ELSE

m = c

END IF

PRINT "Middle no:"; m

END SUB

 

By using FUNCTION procedure ( FUNCTION….END FUNCTION)

DECLARE FUNCTION middle (a, b, c)

CLS

INPUT "Enter first number:"; a

INPUT "Enter second number:"; b

INPUT "Enter third number:"; c

mi = middle(a, b, c)

PRINT "Middle number="; mi

END

 

FUNCTION middle (a, b, c)

IF (a < b AND a > c) OR (a > b AND a < c) THEN

m = a

ELSEIF (b < a AND b > c) OR (b > a AND b < c) THEN

m = b

ELSE

m = c

END IF

middle = m

END FUNCTION

 

Output:




Conclusion:

In conclusion, QBASIC is a programming language that is easy to learn and use, and it can be used for a wide range of applications. In this article, we have learned how to use QBASIC program to enter any three numbers and display the middle number. This program can be useful when working with odd-numbered data sets or when you need to quickly determine the middle value among a set of values. With a basic understanding of QBASIC, you can build upon this program and create more complex applications.

No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages