How to Calculate an Infix Expression
An infix expression in computing is where the mathematical symbol is positioned between the numbers that it is acting on. For example, 3+2 is an infix expression because the addition symbol is placed in between the two numbers that are being added as opposed to being placed in front or behind. The operations in these expressions are carried out in a certain order. If you are typing an expression to be evaluated by the computer in a program, you must know in what order the operations will be performed.
Instructions
-
-
1
Carry out the indicated operations on all the expressions inside parenthesis first. For example, in the expression (5+2) -- 3*3+ 20/2 + 6/3*2 + 6/(3*2) the 5 and the 2 in the first term are added and then the 3 is multiplied by the 2 in the last term so the expression becomes 7-3*3+ 20/2 + 6/3*2 +6/6. If there are nested parenthesis, the innermost parenthesis is worked on first. For example in the expression 2+(3+(4+5)) first the 4 and the 5 are added to give 2+(3+20) and then the 3 and 20 are added next to give 2+23.
-
2
Perform the indicated multiplication or division. In the current example the expression becomes 7 - 9 + 10 + 4 +1. Note that the last two terms are not equal. The expression 6/3*2 does not equal 6/(3*2). The two is read as being in the numerator so the expression is equivalent to (6/3)*2.
-
-
3
Perform addition or subtraction. In the current example 7 - 9 + 10 + 4 +1 =13.
-
1
- Photo Credit maths mark image by Bram J. Meijer from Fotolia.com