basics · beginner · ~15 min
Branch on an operator and guard division.
Implement int apply_op(int a, int b, char op) for op in '+', '-', '*', '/'. For division by zero (or an unknown op) return 0.
int apply_op(int a, int b, char op) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.