in Programming in C
453 views
0 votes
0 votes

in Programming in C
by
453 views

3 Comments

Are these parenthesis right according to given conditions in question?
(((((a+b)+c) x d) x e) - f) - g ^ (h ^ (i ^ j))

If it was to be evaluated
0
0
(((((a+b)+c) x d) x ((e - f) - g)) ^ (h ^ (i ^ j)))
1
1
opton B.... - having heigher precedence than x
0
0

1 Answer

2 votes
2 votes
step 1: evaluate for minus sign

a+b+c*d*[(e-f)-g]^h^i^j               =              a+b+c*d* [(e f - )g -] ^h^i^j

step 2: evaluate for + sign

[(a+b)+c]*d* [(e f - )g -] ^h^i^j         =             [(a b+)c +]*d* [(e f - )g -] ^h^i^j

step 3: evaluate for * sign

  [{[(a b+)c +]*d}* [(e f - )g -]] ^h^i^j       =          [{[(a b+)c +]d*} [(e f - )g -] *] ^h^i^j

step 4: evaluate for ^ sign

 { [{[(a b+)c +]d*} [(e f - )g -] *] ^[h^(i^j)]}      =      { [{[(a b+)c +]d*} [(e f - )g -] *] [h (i j^)^]^}

final output is a b + c + d * e f - g- * h i j ^ ^ ^

option b is correct