Question: I am working on a project and I need help, here is my code but the output is wrong, yet it compiles. #include #include int
I am working on a project and I need help, here is my code but the output is wrong, yet it compiles.

#include
#include
int **allocateMatrix(int, int);
void initMatrix(int **, int, int);
int findRange(int **, int, int);
double findAverage(int **, int, int);
void printCorners(int **, int, int);
int main(int argc, char *argv[])
{
srand(0);
int **data;
int row = atoi(argv[1]);
int col = atoi(argv[2]);
data = allocateMatrix(row, col);
initMatrix(data, row, col);
printf("Range of values in the array is %d ", findRange(data, row, col));
printf("Average of all array values is %lf ", findAverage(data, row, col));
printCorners(data, row, col);
return 0;
}
/*Allocates space for the matrix, returning a pointer to that location in memory.
Recall that to allocate space for the matrix, you:
Declare an int** variable.
Assign that variable to the result of allocating space for the rows in the matrix.
For each row pointer in the matrix, allocate space for all integers on that row.*/
int **allocateMatrix(int row, int col)
{
int **start;
start = malloc(row * sizeof(int *)); //Allocate row number of pointers.
for(int i = 0; i
{
*(start + i) = malloc(sizeof(int) * col); //Allocate col number of integers.
}
return start;
}
/*Initialize all values in the matrix to a random value in the range of 0 - 999*/
void initMatrix(int **start, int row, int col)
{
for(int i = 0; i
for(int j = 0; j
*(*(start + i) + j) = rand() % 1000;
}
/*Calculates and returns the range of the elements in the matrix.
Recall the range of the matrix is the largest value minus the smallest value in the matrix.*/
int findRange(int **start, int row, int col)
{
int max, min;
max = min = **(start);
for(int i = 0; i
for(int j = 0; j
{
if(*(*(start + i) + j) > max)
max = *(*(start + i) + j);
if(*(*(start + i) + j)
min = *(*(start + i) + j);
}
return max - min;
}
/*Calculates and returns the average value (a double) of all elements in the matrix*/
double findAverage(int **start, int row, int col)
{
double sum = 0.0;
for(int i = 0; i
for(int j = 0; j
sum += *(*(start + i) + j);
return sum / (row * col);
}
/*Prints the four values at the corners of the matrix.*/
void printCorners(int **start, int row, int col)
{
printf("%d\t%d %d\t%d ", **start, *(*(start + 0) + col-1), *(*(start + row-1) + 0), *(*(start + row-1) + col-1));
}
CS 100 Lab Seven Spring 2017 Create a directory called lab7 on your machine using mkdir lab7 Within this directory, complete the program named lab7.c that is shown below. You need to write the five functions shown in red #include
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
