成人论坛

Implementation: Computational constructsArithmetic operators (performing calculations)

Programs use computational constructs such as loops and predefined functions to break programs up into sections. This makes programs more compact, easier to write and easier to maintain.

Part of Computing ScienceSoftware design and development

Arithmetic operators (performing calculations)

To perform calculations, computer programmers use arithmetic operators.

Here are some examples of calculations using arithmetic operators and variables:

Add
SET total TO a+b
Adding the value of variable a to the value of variable called b. So if a contained 6 and b contained 2, the value 8 would be assigned to the total variable.
Subtract
SET total TO a-b
Subtracting the value of variable b from the value of variable called a. So if a contained 6 and b contained 2, the value 4 would be assigned to the total variable.
Multiply
SET total TO a*b
Multiplying the value of variable a with the value of variable b. So if a contained 6 and b contained 2, the value 12 would be assigned to the total variable.
Divide
SET total TO a/b
Dividing the value of variable a with the value of variable b. So if a contained 6 and b contained 2, the value 3 would be assigned to the total variable.
Exponent
SET total TO a^b
Raises the value of variable a to the value of variable b. So if a contained 6 and b contained 2, the value of 62 would be assigned to the total variable. In this case 62 is 36, so the value 36 is assigned to the total variable.
Add
SET total TO a+b
Adding the value of variable a to the value of variable called b. So if a contained 6 and b contained 2, the value 8 would be assigned to the total variable.
Subtract
SET total TO a-b
Subtracting the value of variable b from the value of variable called a. So if a contained 6 and b contained 2, the value 4 would be assigned to the total variable.
Multiply
SET total TO a*b
Multiplying the value of variable a with the value of variable b. So if a contained 6 and b contained 2, the value 12 would be assigned to the total variable.
Divide
SET total TO a/b
Dividing the value of variable a with the value of variable b. So if a contained 6 and b contained 2, the value 3 would be assigned to the total variable.
Exponent
SET total TO a^b
Raises the value of variable a to the value of variable b. So if a contained 6 and b contained 2, the value of 62 would be assigned to the total variable. In this case 62 is 36, so the value 36 is assigned to the total variable.