CJCoding With Joseph
15free / daySign inCreate account

Transform an Array Through a Callback Pointer

The function triple is already written for you. Complete this function (the signature is given and must not change):

void apply_to_all(int *values, int n, int (*fn)(int))

It must replace every one of the first n elements of values with the result of calling fn on that element. Do not call triple by name inside it — call it through the fn parameter.

In main, read an integer n (at most 64), then n integers. Call apply_to_all passing triple as the callback, then print all n transformed values on one line, separated by single spaces, with no trailing space.

For the input:

4
1 2 3 4

the output is exactly what is shown in Expected Output.

The line ends with a newline.

Expected Output:

3 6 9 12

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
Pointers
📥 Auto-Input:
4\n1 2 3 4\n
This input is automatically fed to your program's stdin
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (p, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.