Arithmetic Dispatch Table of Function Pointers
mediumQuestion 464The four operations and their names are already written for you. Build a dispatch table
int (*ops[4])(int, int) = { add, sub, mul, max_of };
and use it to run the commands from input.
Input: the first line is commands, the number of commands that follow. Each command is three integers on its own line: an operation code (0 = add, 1 = sub, 2 = mul, 3 = max) and the two operands a and b.
For each command print one line in exactly this form:
name(a, b) = result
using the matching entry of the names array.
For the input:
3 0 6 3 2 4 5 3 9 -2
the output is exactly what is shown in Expected Output.
Each line ends with a newline. Do not use if/else or switch to pick the operation — index the table.
Expected output
add(6, 3) = 9 mul(4, 5) = 20 max(9, -2) = 9
= newline. The output ends with a newline, so print one after the last line.
Your output
Run your code to see the output here...