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

Write the following functions Void printMatrix (int n, m, int A[] [m], which pri

ID: 3812682 • Letter: W

Question

Write the following functions Void printMatrix (int n, m, int A[] [m], which prints the values of a nxm matrix to the screen. void setup RandMatrix (int n, int m int A[] (m), int min int max) which a random values to an nxm matrix. Each random number is between min and max. int get Rowsum (int n int m, int All [m], int row) which returns sum of the growth row of an the non-dimensional matrix void get rages (int n, int m float A[] [m] float a [] [m], which returns all of the row sums of a matrix. void interchange Rows (int n int m, int A (m), int row1, int row2) which interchanges the values of row1 and row2.

Explanation / Answer

Here is code:


void printMatrix(int n,int m,int A[][m])
{
int i,j;
for(i =0 ; i < n ; i++) // outer loop
{
for(j = 0 ; j < m ; j++) // inner loop
{
printf("%d ",A[i][j]);
}
printf(" ");
}
  
}

void setupRandMatrix(int n,int m,int A[][m],int min,int max)
{
int i,j;
srand(time(NULL));
for(i =0 ; i < n ; i++) // outer loop
{
for(j = 0 ; j < m ; j++) // inner loop
{
A[i][j] = (rand() % (max + 1 - min)) + min;
}
}
  
}

int getRowSum(int n,int m,int A[][m],int row)
{
int j;
int sum = 0;
for(j = 0 ; j < m ; j++) // outer loop
{
sum += A[row][j];
}
return sum;
}

void getRowAverages(int n,int m,int A[][m],float ave[])
{
int i,j;
int sum[n]; // sum each row
for(i =0 ; i < n ; i++) // outer loop
{
sum[i] = 0;
for(j = 0 ; j < m ; j++) // inner loop
{
sum[i] += A[i][j];
}
ave[i] = (float)sum[i]/m;
}
  
}


void interchangeRows(int n,int m,int A[][m],int row1,int row2)
{
int i,j;
int temp;
for(i = 0 ; i < m ; i++) // outer loop
{
// swap elements
temp = A[row2][i];
A[row2][i] = A[row1][i];
A[row1][i] = temp;
}
  
}