Factory Function Returns a Heap Array
mediumQuestion 455Write 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, so print one after the last line.
Hints4 available
Sign in to use hintsTopics
Pointers
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.