Question: Write a program that asks the user to enter an integer n , followed by a series of n numbers and then it prints the

Write a program that asks the user to enter an integer n, followed by a series of n numbers and then it prints the average of the numbers. Your program must use dynamic memory allocation functions to allocate the array, as well as de-allocate the array after average value is calculated.
The program should behave as follows (items underlined are entered by the user):
Enter an integer: 4
Enter 4 numbers: 1234
The average is: 2.5
Algorithm design process:
1. Declare your variables. Most importantly you would need a variable of the type pointer to int (call it array) to store the address of the memory block returned by the dynamic memory allocation functions. This pointer will store the address of the memory block where you will put the numbers entered by the user.
2. Prompt the user and read in the value of n.
3. Use malloc/calloc to allocate an integer array of size n, assign the return value to your pointer variable array, then read the integer values from the user into array.
4. Compute the average of the integer values (should be a float) and print it.
5. Free up the memory block that was allocated for the integer values (the array pointer).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!