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

Friday, December 2, 2022

QBASIC program to display the average of input two numbers

 QBASIC program to display the average of input two numbers



QBASIC program to display the average of input two numbers


Introduction: 

Are you looking to create a program in QBASIC that can display the average of two numbers? Look no further! QBASIC is a simple yet powerful programming language that can help you achieve this task with ease. In this article, we will provide you with a step-by-step guide on how to create a QBASIC program to display the average of input two numbers. Whether you are a beginner or an experienced programmer, our guide will help you write your own program in no time.


Understanding QBASIC Programming Language


Before we dive into creating our program, it's important to understand the basics of QBASIC programming language. QBASIC is a high-level programming language that was developed by Microsoft for use with their DOS operating system. QBASIC uses simple and easy-to-understand syntax, making it a popular choice for beginners.

Coding for QBASIC program to display the average of input two numbers

CLS

INPUT "Enter first number:"; x

INPUT "Enter second number:"; y

p = (x + y) / 2

PRINT "Average of two numbers="; p

END



Explanation:

  1. The program begins with the CLS command, which clears the screen.
  2. The next two lines prompt the user to enter two numbers using the INPUT command. The first number is stored in the variable x and the second number is stored in the variable y.
  3. The program then calculates the average of the two numbers using the formula p = (x + y) / 2, and stores the result in the variable p.
  4. The final line uses the PRINT command to display the calculated average to the user.
  5. The program then ends with the END command.


We can write the above program by using SUB and FUNCTION Procedures

By using SUB procedure (SUB..END SUB)

DECLARE SUB average (x, y)

CLS

INPUT "Enter first number:"; x

INPUT "Enter second number:"; y

CALL average(x, y)

END

 

SUB average (x, y)

p = (x + y) / 2

PRINT "Average of two numbers="; p

END SUB

 

By using FUNCTION procedure (FUNCTION…END FUNCTION)

DECLARE FUNCTION average (x, y)

CLS

INPUT "Enter first number:"; x

INPUT "Enter second number:"; y

PRINT "Average of two numbers="; average(x, y)

END

 

FUNCTION average (x, y)

average = (x + y) / 2

END FUNCTION


Output:





FAQs:



Q. What is QBASIC programming language?
Ans: QBASIC is a high-level programming language developed by Microsoft for use with their DOS operating system.

Q. What are variables in QBASIC?
Ans: Variables in QBASIC are used to store data values. They are declared using the "DIM" statement followed by the variable name and its data type.

Q. How do I get input from the user in QBASIC?
Ans: In QBASIC, you can use the "INPUT" statement to get input from the user.


Q. How do I display output to the user in QBASIC?
Ans: In QBASIC, you can use the "PRINT" statement to display output to the user.




Conclusion:


In this article, we have provided you with a step-by-step guide on how to create a QBASIC program to display the average of input two numbers. We have explained the basic syntax of QBASIC and demonstrated how to declare variables, get input from the user, calculate the average, and display output to the user. With this easy-to-follow guide, you can write your own QBASIC program in no time. QBASIC is a great language for beginners to learn, and this program is a great example of its simplicity and power. We hope this article has been helpful to you, and we wish you the best of luck in your programming endeavors!

No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages