Sum and Average on the Heap
MediumRead a count n between 1 and 1000, allocate an int array of exactly n elements with malloc, check the result against NULL (print "allocation failed" and return 1 if it is), read n values with guarded scanf, then print the sum and the average to two decimal places, casting before dividing. Free the block before returning: this exercise fails on a memory leak even when the output is byte-perfect, so every path that owns the block must release it.
Success Criteria
Your code must pass 3 test case(s) to complete this exercise. 3 hint(s) are available if you need help.
Sign in to track your progress
You can work on exercises as a guest, but sign in to track your progress and save your submissions.
How did you find this exercise?
Your rating helps us improve the content.