Arithmetic Operation

You are given two integers a and b, and an operator op.

The task is to perform the operation a op b and return the result as an integer.

Example 1:

Input: a = 5, b = 2, op = +

Output: 7

Explanation: The operation is +, so we peform 5+2 =7

Example 2:

Input: a = 9, b = 4, op = %

Output: 1

Explanation: The operation is %, so we peform 9%4 =1

Now Your Turn!

Pick the correct output for the given input

Input: a = 10, b = 3, op = /

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • -100 ≤ a, b ≤ 100
  • op ∈ {+, -, *, /, %}
0
 
 
class Solution{
public:
int operate(int a, int b, char op){
}
};
Test Case

Input:

A
B
Op