Arithmetic operations, or calculations, are an important part of programming. Almost every program includes at least a few arithmetic operations.
Visual Basic has the following operators:
| Operator | Use | Example | Result |
| + | Addition | 5 + 2 | 7 |
| - | Subtraction | 5 - 2 | 3 |
| * | Multiplication | 3 * 5 | 15 |
| / | Division (result is double) | 17 / 5 | 3.5 |
| \ | Integer Division | 17 \ 5 | 3 |
| ^ | Raising to a Power | 2 ^ 3 | 8 |
| Mod | Remainder | 17 Mod 5 | 2 |
The Mod (modulus) operator is used to find the remainder. Before children learn about decimal numbers, they may give the answer to the question "How much is 17 divided by 5?" as: 17 divided by 5 is 3 with a remainder of 2. Note that 17/5 results in 3.5, 17\5 results in 3, while 17 mod 5 results in 2.
Answer the Mod problems until you feel that you understand Mod. To use this exercise, just type the answer in the box with a border, then press Enter on the keyboard. There is one tricky thing to these question with Mod: if the first value is less than the second, the answer is the same as the first number. For example, 7 Mod 10 is 7.
INDEX, Arithmetic Operations, Modulus Operator, Order of Operations, Functions, Algebra to Code
Next lesson: Visual Basic Variables