The postfix form of the expression (a+ b)*(c*d- e)*f / g is?
Answers
Answer:
(ab+)(cd*e-)fg/**
Step-by-step explanation:
Points to be kept in mind:
1) Left-to-right associativity.
2) /,* are given priority when compared to +,-
3) Postfix expressions are useful when calculations are to be done in a stack.
Simple example:
A * B + C
The postfix form of the above expression will be;
Since, * is given the highest priority here
AB * + C
Next priority is for the + operator.
AB * C +
This means that A and B are to be multiplied and C is added to the result.
The postfix expression shows the operator after the variable, but the operation is the same.
I we say A + B,
The resultant calculation will be A + B
But shown as AB +, which means A and B are added.
Given expression;
(a+b) * (c*d-e) * f / g
Priority to ‘/‘ operator
(a+b) * (c*d-e) * fg/
Priority to brackets and ‘*’ operator
(a+b)(c*d-e)fg/**
Priority to ‘*’ operator
(a+b)(cd*-e)fg/**
Priority to ‘+’ and ‘-’ operators
(ab+)(cd*e-)fg/**
Now, let us check the calculation;
1) a and b are added,
2) c and d are multiplied and subtracted by e,
3) f is divided by g
4) Results from steps 1, 2, 3 are multiplied.
Which brings us,
(a+b) * (c*d-e) * f / g
AB+CD*E-*F*G/
Precedence should be given in the following order
1) Parnthesis and brackets
2)Exponents from right to left
3)*,/ from left to right
4)+,- from left to right