← Dynamic Memory: malloc, free & the Stack vs. the Heap

Heap Squares

easy

Read n, malloc an array of n ints on the heap, fill it with the squares 0*0, 1*1, 2*2, ..., print them space-separated on one line, and free the array.

This is deliberately the same shape as earlier array exercises – the only new part is that the array’s storage comes from malloc instead of being declared with a fixed compile-time size like int values[100]. Everything else (indexing, looping, printing) works identically once you have the pointer back from malloc.

Your solution

"Run" uses the sample stdin ("5"). "Submit" checks your code against all 3 test cases.

Test results

Submit your solution to run it against all test cases.

Hints

    Reference solution