Expression | 8 + 2 / 2 + 3 | (8 + 2) / (2 + 3) | (8 + 2) / 2 + 3 | 8 + 2 / (2 + 3) |
---|---|---|---|---|
Value? | 12 | 2 | 8 | 8 |
The last answer is correct. It is done like this:
8 + 2 / (2 + 3 ) -------- 8 + 2 / 5 ----- 8 + 0 ----- 8
2/5
is 0
with integer division.
Sometimes in a complicated expression one set of parentheses is not enough. In that case use several nested sets to show what you want. The rule is:
The innermost set of parentheses is evaluated first.
Start evaluating at the most deeply nested set of parentheses, and then work outward until there are no parentheses left. If there are several sets of parentheses at the same level, evaluate them left to right. For example:
( ( ( 32 - 16 ) / ( 2 * 2 ) ) - ( 4 - 8 ) ) + 7 ----------- ( ( 16 / ( 2 * 2 ) ) - ( 4 - 8 ) ) + 7 --------- ( ( 16 / 4 ) - ( 4 - 8 ) ) + 7 --------------------------- ( 4 - ( 4 - 8 ) ) + 7 ------- ( 4 - -4 ) + 7 --------------------------------------------- 8 + 7 ---------------------------- 15
Ordinarily you would not do this in such detail.
What is the value of this expression:
(12 / 4 ) + ( 12 / 3)