QBASIC program to display the average of input two numbers
Introduction:
Understanding QBASIC Programming Language
CLS
INPUT
"Enter first number:"; x
INPUT
"Enter second number:"; y
p
= (x + y) / 2
PRINT
"Average of two numbers="; p
END
Explanation:
- The program begins with the CLS command, which clears the screen.
- 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.
- 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.
- The final line uses the PRINT command to display the calculated average to the user.
- The program then ends with the END command.
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.
No comments:
Post a Comment