Rules of Precedence (Machine Problem)

0

Written on Tuesday, May 06, 2008 by Ennah, the comsci student

Assume the following rules of precedence for expressions:
Highest is addition (+)
then subtraction (-)
then multiplication (*)
then division (/)

Evaluate inputs such as:
(a) 1+4*3-2/2 Output: 5*3-2/2 = 5*1/2 = 5/2 = 2.5
(b) 5-2/2+1*2 Output: 5-2/3*2 = 3/3*2 = 3/6 = 0.5
(c) 3-2+4-2+5 Output: 3-6-7 = -3 - 7 = -10




If you enjoyed this post Subscribe to our feed

No Comment

Post a Comment