Here's yet another classical problem in programming. This problem is not language specific, although I would strongly advice using C or C++.
Reverse Polish Notation
From Wikipedia:
"The Reverse Polish Notation (RPN) is a mathematical notation wherein ever operator follows all of its operands".
An example is often worth a thousand words. So there goes:
( 5 + ( ( 3 * 13 ) + 1 ) ) / 9
is equivalent to:
5 3 13 * 1 + + 9 /
And here are the steps to resolve this equation:
5 39 1 + + 9 /
5 40 + 9 /
45 9 /
5
Take a look at each step, and you'll understand how this notation works.
Exercise
Develop a RPN Calculator, a program that would take as an input a RPN string and would output the result.
Then use this program to give the result of:
23 76 66 + * 56 8 / - 13 12 * -
31 54 57 + 102 - * 76 12 3 + *
1 34 26 57 + - 49 + / 13 8 - 7 * 5 65 - -
Reverse Polish Notation
From Wikipedia:
"The Reverse Polish Notation (RPN) is a mathematical notation wherein ever operator follows all of its operands".
An example is often worth a thousand words. So there goes:
( 5 + ( ( 3 * 13 ) + 1 ) ) / 9
is equivalent to:
5 3 13 * 1 + + 9 /
And here are the steps to resolve this equation:
5 39 1 + + 9 /
5 40 + 9 /
45 9 /
5
Take a look at each step, and you'll understand how this notation works.
Exercise
Develop a RPN Calculator, a program that would take as an input a RPN string and would output the result.
Then use this program to give the result of:
23 76 66 + * 56 8 / - 13 12 * -
31 54 57 + 102 - * 76 12 3 + *
1 34 26 57 + - 49 + / 13 8 - 7 * 5 65 - -