#include #include #include int main(void) { double *values = NULL; /* Pointer to memory holding data values */ double *temp = NULL; /* Pointer to newly allocated memory */ double sum = 0.0; /* Sum of values */ int capacity = 0; /* Maximum number of values that can be stored */ int increment = 5; /* Capacity increment for dynamic allocation */ int count = 0; /* Number of values read */ char answer = 'n'; do { if(count == capacity) /* Check if there is spare memory */ { capacity += increment; /* Increase the capacity of memory by increment */ temp = (double*)malloc((capacity)*sizeof(double)); /* and allocate it */ if(!temp) /* If memory was not allocated */ { /* Output a message and end */ printf("Memory allocation failed. Terminating program."); exit(1); } if(!values) /* Are there any values? */ values = temp; /* No - so just copy address of new memory */ else /* Yes - so copy data from old to new */ { for(int i = 0 ; i