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 deallocate the array after average value is calculated.
The program should behave as follows items underlined are entered by the user:
Enter an integer:
Enter numbers:
The average is:
Algorithm design process:
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.
Prompt the user and read in the value of n
Use malloccalloc 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.
Compute the average of the integer values should be a float and print it
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
