Question
/** * Statistics main driver program * Arrays & Dynamic Memory Lab * CSCE 155E */ #include #include #include stats.h #define MAX_SIZE 100 int main(void)
/**
* Statistics main driver program
* Arrays & Dynamic Memory Lab
* CSCE 155E
*/
#include
#include
#include "stats.h"
#define MAX_SIZE 100
int main(void) {
//pay no attention to the man behind the curtain
srand(time(NULL));
int min, max, size;
double mean;
printf("Enter the amount of numbers you'd like to find the stats for: ");
scanf("%d", &size);
if(size > MAX_SIZE) {
printf("ERROR: program does not support that many integers!");
exit(1);
}
//TODO: declare a static array "large enough" to hold as many integers as we'll need
//TODO (Activity 3): change your delcaration and initialization to use
// a dynamic array and malloc instead
int *arr = (int *) malloc(sizeof(int) * size);
arr = createRandomArray(size);
//TODO: pass the appropriate variable
readInArray(arr, size);
//TODO: pass the appropriate variables to your functions here
min = getMin(arr,size);
max = getMax(arr,size);
mean = getMean(arr,size);
printArray(arr,size);
printf("Min: %d ", min);
printf("Max: %d ", max);
printf("Mean: %.2f ", mean);
return 0;
}
Activity 4: Dynamic Arrays In this activity you will modify the code in statsMain.c to use a dynamic array instead of a static array. Instructions Alter your static array declaration to be an integer pointer and add code that calls malloc to initialize the appropriate amount of memory. Alter any other code as necessary to remove the "large enough" restriction that we had in the previous activity Run your program again and demonstrate it to a lab instructor 1. 2. 3Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started