Since we are going to perform some computations, let us recall the basic operation, operators, and aperands.
The table below discusses the operators, the symbols used, some examples and their results.
Meaning |
Operator (symbol used in the computer) |
Sample |
Result |
1. Addition |
+ |
45 + 8 |
53 |
2. Subtraction |
- |
137 – 25 |
112 |
3. Multiplication |
*(asterisk) |
34 * 87 |
2958 |
4. Division |
/ |
75 / 3 |
25 |
5. Integer Division |
\ |
64 \ 3 |
21 |
6. Remainder after Division |
MOD |
8 MOD 3 |
2 |
7. Exponentiation |
^(caret) |
3 ^ 2 |
9 |
Instead of an x for multiplication, the computer uses the asterisk(*) symbol. This is found on the top of the number 8 key in the keyboard. Just press the SHIFT button plus the number 8 key. The ramainder after division is also called modular division. When making calculations using modular division, just type the three letters MOD. For the exponentiation, look for the caret(^) sign found on the top of the number 6 key in the keyboard. Same with the asterisk, just press SHIFT together with the number 6 key.
Order of Operation
The Computer also follows the left to Right rule and PEMDAS rule in math when evaluating arithmetic expressions. PEMDAS means Parenthesis, Exponent, Multiplication, Division, Addition, and Subtraction.
The table below shows the priority of the operation. The highest priority is what comes first.
Operation |
Operator (symbol used in the computer) |
1. Exponent |
^ |
2. Multiplication, Division |
*(asterisk), / |
3. Integer Division |
\ |
4. Modular (remainder after division) |
MOD |
5. Addition, Subtraction |
+, - |
NUMBERS
Computers are very good at math. Let's get the computer to do some math for us. Here's a simple multiplication calculator:
CLS
INPUT "Enter the first number: ", A
INPUT "Enter the second number: ", B
PRINT "The answer is: "; A * B
If you have trouble finding the star (or asterisk "*") on the keyboard, it is usually above the number 8. Run it, and enter two numbers. It does an excellent job multiplying for you.
Variables and Math
A and B are variables, just like Name$. Unlike Name$, A and B do not have a dollar-sign after their names. This is because they are only holding numbers, not letters.
Star
"A * B" means "A times B". QBASIC doesn't use "X" for multiplication because you might want to have a variable called "X".
What else?
Try changing the "A * B" to "A - B" for subtraction. "A + B" will do addition, and "A / B" will do division. Why "/" for division? Because there's no division sign key on the keyboard. At least I haven't found one.
Expressions
"A * B", "A + B", "A - B", and "A / B" are called mathematical expressions, or simply "expressions".
Learned
- Variables with numbers
- INPUT with numbers
- Multiplication, Division, Addition, Subtraction
- Expressions
Source: http://jpsor.ucoz.com