38. Function Pointer apply

 You are given two functions already defined:

int square(int x) { return x * x; }
int cube(int x) { return x * x * x; }

 

In main(), these functions are already called using a function pointer.

Your task is to write the function:

void apply(int x, int (*op)(int))
  • It should call op(x) and print the result.

     

Example
 Input:

5 square

Output:

25

 

Input:

3 cube

Output:

27
Loading...

Input

5 square

Expected Output

25