CJCoding With Joseph
15free / daySign inCreate account

Factory Function Returns a Heap Array

Write make_squares(n) so it returns a heap array of n ints where element i holds (i + 1) * (i + 1).
Then in main: read n, call make_squares, print every value on its own line, print "Total: <t>" where <t> is their sum, and free the array in MAIN.

For the input:

4

the output is exactly what is shown in Expected Output.

Free the memory you allocate before the program ends — this question checks for memory leaks.

Expected Output:

1
4
9
16
Total: 30

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

Hints4 available
Topics:
Pointers
📥 Auto-Input:
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.