← Back to Pointers
Question 451
Heap Array Sized by the User
Heap Array Sized by the User
Read an integer n from input, then read n more integers. Allocate an int array of exactly n elements with malloc, store the values in it, and then print: - each stored value MULTIPLIED BY 2, one per line, in the order they were read - a final line "Sum:<s>" where<s>is the sum of the ORIGINAL (not doubled) values For the input: 4 5 1 9 3 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:
10 2 18 6 Sum: 18
= newline. The output ends with a newline — 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.