0
$\begingroup$

Possible Duplicate:
What is 48÷2(9+3)?

I was having a heated debate with my colleague and we can't agree on the answer to this question: Does 6÷2(2+1) equal 9 or does it equal 1?

  • 2
    The textbook answer is that operations of equal precedence are performed from left to right in the absence of parentheses, so the result is $9$. The real answer is that the expression equals *the writer is incompetent*: in the real world it’s ambiguous, and the ambiguity is sufficiently obvious that failure to avoid it is inexcusable sloppiness.2012-09-18

1 Answers 1

1

Depends on whether $6 \div 2 \times (2+1)$ means $(6 \div 2) \times (2+1)$ or $6 \div (2 \times (2+1))$. The former yields $9$, the latter $1$. In a programming language like Haskell, the ambiguity would be resolved by specifying what the priority of each operator is, and whether such operator is left- or right-associative.

Remark: Note that in this context, an operator is a binary arithmetic operation. Thus, addition, subtraction, multiplication, and division are operators.