teach-ict.com logo

THE education site for computer science and ICT

3. Arithmetic operators continued.

On the previous page we discussed common arithmetic operators that you are already familiar with. They use symbols for which you instantly recognise their meaning.

However in programming, there are a few less common arithmetic operations that you will also need to learn.

Exponential

This means raising a number up to the power of another number. The operator symbol for this usually ^ or sometimes EXP

A statement such as

SET x TO 2^3

means 2 raised to the power of three ($2^3$, or 2 x 2 x 2). Exponentiation always raises the number on the left by the power of the number on the right.

DIV (Quotient or 'integer division')

DIV is an operator that calculates how many times one number can be divided by another, discarding remainders.

For example:

SET x TO 20 DIV 3

DIV works out how many times the number on the left (20) can be divided by the number on the right (3), and returns the result.

In this case the value of x is 6, since 20 can be divided by 3 six times.

 

MOD (Modulus)

The "Modulus" operation does the same thing as DIV, but, instead of returning the number of divisions, it returns the remainder. In pseudocode, the symbol used for modulus is MOD.

For example:

SET Remainder TO 10 MOD 3

Since 3 goes into 10 three times with 1 left over, the modulus operation returns "1" as the answer.

Challenge see if you can find out one extra fact on this topic that we haven't already told you

Click on this link: What are arithmetic operators?