Click 'Run' to go.
The arithmetic operations of addition, subtraction, multiplication, and division have an order. When an arithemetic expression has more than one operation, and it has no parentheses, then there are rules that state which operations go first and which operations go next. These rules are called the rules of precedence. To see this situation we will present a simple arithmetic expression:
2 + 3 * 4
One might read this, "Two plus three times four."
To correctly calculate the result, you need to know the rules of precedence. They are:
So, for the above example we would first calculate three times four (since multiplications happen first) and get twelve. Then we would add two and twelve (since additions happen second) and get a final result of fourteen:
2 + 3 * 4 = 2 + 12 = 14
Use the programing demo below to experiment with how this precedence works. These rules of precedence are present in most common computer languages.
Raising to a power is often called a math operation, and it would have the highest order of precedence, above even multiplication and division. In some languages, such as BASIC or those found on handheld calculators, raising to a power is notated with a caret or up arrow. So, 2 raised to the 3 power could look like this:
As it turns out, when combined with other operators or negative values, the above notation can be confusing. Some computer languages, such as C and Java, simply opt for considering raising to a power to work like a function call. So, 2 raised to the 3 power can look like this:
The flowchart for this demo looks like this:
Here is how this could appear in an imaginary computer language:
print(2 + 3 * 4);
Suggested next article:
The following article is related to this demo: