Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am writing a code and I need help, it compiles but I get the wrong output, it

ID: 3801628 • Letter: I

Question

I am writing a code and I need help, it compiles but I get the wrong output, it doesn't match up with what I have to get when I do ./a.out 2 2, please help.

#include<stdio.h>
#include<stdlib.h>

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 value in the array is %d ",findRange(data,row,col));
    printf("Average of all array values is %1f ",findAverage(data,row,col));
    printCorners(data,row,col);
    return 0;
}

int** allocateMatrix(int row,int col)
{
    int **arr = (int **)malloc(row * sizeof(int *));
    int i;
    for (i=0; i<row; i++)
         arr[i] = (int *)malloc(col * sizeof(int));
    return arr;
}
void initMatrix(int** data,int row,int col)
{
    int i,j;
    for(i=0;i<row;i++)
    {
        for(j=0;j<col;j++)
        {
            data[i][j]=rand()%1000;
        }
    }
}
int findRange(int** data,int row,int col)
{
    int i,j;
    int max=data[0][0];
    int min=data[0][0];
    for(i=0;i<row;i++)
    {
        for(j=0;j<col;j++)
        {
            if(data[i][j]>max)
                max=data[i][j];
            if(data[i][j]<min)
                min=data[i][j];
        }
    }
    return (max-min);
}
double findAverage(int** data,int row,int col)
{
    double d=0;
    int i,j;
    for(i=0;i<row;i++)
    {
        for(j=0;j<col;j++)
        {
            d+=data[i][j];
        }
    }
    d=d/(row*col);
    return d;
}
void printCorners(int** data,int row,int col)
{
    printf(" %d %d",data[0][0],data[0][col-1]);
    printf(" %d %d",data[row-1][0],data[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

Explanation / Answer

//This is providing currect output only , If not please comment with example

#include<stdio.h>
#include<stdlib.h>

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]);
    //int row=atoi("2");
    //int col=atoi("2");

    data=allocateMatrix(row,col);
    initMatrix(data,row,col);
    printf("Range of value in the array is %d ",findRange(data,row,col));
    printf("Average of all array values is %1f ",findAverage(data,row,col));
    printCorners(data,row,col);
    return 0;
}

int** allocateMatrix(int row,int col)
{
    int **arr = (int **)malloc(row * sizeof(int *));
    int i;
    for (i=0; i<row; i++)
         arr[i] = (int *)malloc(col * sizeof(int));
    return arr;
}
void initMatrix(int** data,int row,int col)
{
    int i,j;
    for(i=0;i<row;i++)
    {
        for(j=0;j<col;j++)
        {
            data[i][j]=rand()%1000;
        }
    }
}
int findRange(int** data,int row,int col)
{
    int i,j;
    int max=data[0][0];
    int min=data[0][0];
    for(i=0;i<row;i++)
    {
        for(j=0;j<col;j++)
        {
            if(data[i][j]>max)
                max=data[i][j];
            if(data[i][j]<min)
                min=data[i][j];
        }
    }
    return (max-min);
}
double findAverage(int** data,int row,int col)
{
    double d=0;
    int i,j;
    for(i=0;i<row;i++)
    {
        for(j=0;j<col;j++)
        {
            d+=data[i][j];
        }
    }
    d=d/(row*col);
    return d;
}
void printCorners(int** data,int row,int col)
{
    printf(" %d %d",data[0][0],data[0][col-1]);
    printf(" %d %d",data[row-1][0],data[row-1][col-1]);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote