Question
This is the code: stats.c: #include #include #include stats.h //TODO: fix the error in this function void readInArray(int *arr, int size) { int i; printf(Enter
This is the code:
stats.c:
#include
#include
#include "stats.h"
//TODO: fix the error in this function
void readInArray(int *arr, int size) {
int i;
printf("Enter your list of numbers: ");
for (i = 0; i
//
scanf("%d", &arr[i]);
}
return;
}
int * generateRandomArray(int size) {
int * randomArr = malloc(sizeof(int) * size);
for(int i=0; i randomArr[i] = rand(); } return randomArr; } void printArray(const int *arr, int size) { printf("["); for(int i=0; i printf("%d, ", arr[i]); } printf("%d ] ", arr[size-1]); } //change the getMean function to get parameters as array and size,CHEGGEA double getMean( const int *arr,int size ) //double getMean( , ) { { double sum=0; int i; for(i = 0; i { sum+=arr[i]; } return sum/size; } //change the getMean function to get parameters as array and size,CHEGGEA int getMin( const int *arr,int size ) //int getMin( , ) { { int i; int min=arr[0]; for(i = 0; i { if(min > arr[i]) min=arr[i]; } return min; } //change the getMean function to get parameters as array and size,CHEGGEA int getMax(const int *arr ,int size ) //int getMax( , ) { int i; int max=arr[0]; for(i = 0; i { if(max max=arr[i]; } return max; } =================== stats.h /** * This function prompts and reads in a collection of numbers * from the standard input and populates the given array. The * provided array must be properly initialized for this function * to work. */ void readInArray(int *arr, int size); /** * Generates a random array of integers of the given * size. This function assumes that the random number * generator has already been seeded. */ int * generateRandomArray(int size); /** * Prints the given array to the standard output */ void printArray(const int *arr, int size); /* * TODO: * 1. Write prototypes for each of these functions * 2. Write documentation for each of these functions * 3. Implement the functions in stats.c */ //added parameters to the following functions double getMean( const int *arr,int size ); int getMin( const int *arr,int size ); int getMax(const int *arr ,int size ); ================ This what was given for statsMain.c: /** * Statistics main driver program */ #include #include "stats.h" #define SIZE 500 int main(int argc, char** argv) { //seed the random number generator with the current time 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 //TODO: pass the appropriate variable readInArray(, size); //TODO: pass the appropriate variables to your functions here min = getMin( , ); max = getMax( , ); mean = getMean( , ); printArray( , ); printf("Min: %d ", min); printf("Max: %d ", max); printf("Mean: %.2f ", mean); return 0; } What should I do for statsMain.c
Step 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