← Operators & Expressions

Precedence Puzzle

medium

Read four integers a b c d and print the result of evaluating exactly this expression, with C’s normal operator precedence (not left-to-right):

a + b * c - d % 3

Print it in the form Result: 13.

The point of this exercise isn’t the arithmetic – it’s building the habit of reading an expression the way the compiler does. *, /, and % all sit at the same precedence level, one level tighter than + and -. So before you write a single line of code, work out on paper what 2 + 3 * 4 - 7 % 3 should evaluate to, then check your program agrees. If you’re tempted to add parentheses to “help” – don’t; the exercise is to trust precedence, not route around it.

Your solution

"Run" uses the sample stdin ("2 3 4 7"). "Submit" checks your code against all 3 test cases.

Test results

Submit your solution to run it against all test cases.

Hints

    Reference solution