CJCoding With Joseph
15free / daySign inCreate account

Size a Heap Array from cin Input

The program already reads one integer n from input (n is always 1 or more). Allocate a heap array of n ints and store it in the pointer squares, then fill it inside the loop that is already written: squares[i] must hold (i + 1) squared, so index 0 holds 1, index 1 holds 4, index 2 holds 9, and so on.

The printing loop is already written.

If the input is:

5

Print exactly what is shown in Expected Output.

If the input is 3, print exactly:

Squares: 1 4 9

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

Expected Output:

Squares: 1 4 9 16 25

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

Hints3 available
Topics:
Pointers
📥 Auto-Input:
5\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 (cout, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.