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

PLEASE use C code to do the following. Thank you! Create a script that will calc

ID: 3682170 • Letter: P

Question

PLEASE use C code to do the following. Thank you!

Create a script that will calculate the sum of row elements, the sum of column elements, and replace the whole row or column by given row or column vector. i.e. When you were given the followings, A = [a_11 a_12 a_13 a_21 a_22 a_23 a_31 a_32 a_33], B = [b_1 b_2 b_3] You need to create A_row_sum = [a_11 + a_12 + a_13 a_21 + a_22 + a_23 a_31 + a_32 + a_33] A_column_sum = [a_11 + a_21 + a_31, a_12 + a_22 + a_32, a_13 + a_23 + a_33] A_sum = [a_11 a_12 a_12 a_11 + a_12 + a_13 a_21 a_22 a_23 a_21 + a_22 + a_23 a_31 a_32 a_33 a_31 + a_32 + a_33 a_11 + a_21 + a_31, a_12 + a_22 + a_32, a_13 + a_23 + a_33 0], A_B col 1 = [b_1 a_12 a_13 b_2 a_22 a_23 b_3 a_32 a_33], A_B col 2 = [a_11 b_1 a_13 a_21 b_2 a_23 a_31 b_3 a_33], A_B col 3 = [a_11 a_12 b_1 a_21 a_22 b_2 a_31 a_32 b_3] A_B row 1 = [b_1 b_2 b_2 a_21 a_22 a_23 a_21 a_32 a_33], A_B col 2 = [a_11 a_12 a_13 b_1 b_2 b_3 a_31 a_32 a_33], A_B col3 = [a_11 a_12 a_13 a_21 a_22 a_23 b_1 b_2 b_3]

Explanation / Answer

Here is the code for you:

#include <stdio.h>
void readMatrix(int A[][3], int r, int c)
{
for(int i = 0; i < r; i++)
for(int j = 0; j < c; j++)
scanf("%i", &A[i][j]);
}
void printMatrix(int A[][3], int r, int c)
{
for(int i = 0; i < r; i++)
{
for(int j = 0; j < c; j++)
printf("%3d ", A[i][j]);
printf(" ");
}
}
int main()
{
int A[3][3], B[3][1];
printf("Enter the elements into matrix A of size 3x3: ");
readMatrix(A, 3, 3);
printf("Enter the elements into matrix B of size 3x1: ");
readMatrix(A, 3, 1);
int row_Sum[3][1];
printf("Row wise sum matrix is: ");
for(int i = 0; i < 3; i++)
{
row_Sum[i][0] = 0;
for(int j = 0; j < 3; j++)
row_Sum[i][0] += A[i][j];
}
for(int i = 0; i < 3; i++)
printf("%4i ", row_Sum[i][0]);
int colSum[1][3];
printf("Column wise sum matrix is: ");
for(int i = 0; i < 3; i++)
{
colSum[0][i] = 0;
for(int j = 0; j < 3; j++)
colSum[0][i] += A[j][i];
}
for(int i = 0; i < 3; i++)
printf("%4i ", colSum[0][i]);
printf(" ");
int Sum[4][4];
printf("Both row and column sum is: ");
for(int i = 0; i < 3; i++)
{
Sum[i][3] = Sum[3][i] = 0;
for(int j = 0; j < 3; j++)
{
Sum[i][3] += A[i][j];
Sum[3][i] += A[j][i];
}
}
for(int i = 0; i < 4; i++)
{
for(int j = 0; j < 4; j++)
printf("%4i ", Sum[i][j]);
printf(" ");
}
int BCol1[3][3];
printf("BCol1: ");
for(int i = 0; i < 3; i++)
for(int j = 0; j < 3; j++)
if(j == 0)
BCol1[i][j] = B[i][0];
else
BCol1[i][j] = A[i][j];
printMatrix(BCol1, 3, 3);
int BCol2[3][3];
printf("BCol2: ");
for(int i = 0; i < 3; i++)
for(int j = 0; j < 3; j++)
if(j == 1)
BCol2[i][j] = B[i][0];
else
BCol2[i][j] = A[i][j];
printMatrix(BCol2, 3, 3);
int BCol3[3][3];
printf("BCol3: ");
for(int i = 0; i < 3; i++)
for(int j = 0; j < 3; j++)
if(j == 2)
BCol3[i][j] = B[i][0];
else
BCol3[i][j] = A[i][j];
printMatrix(BCol3, 3, 3);
int BRow1[3][3];
printf("BRow1: ");
for(int i = 0; i < 3; i++)
for(int j = 0; j < 3; j++)
if(i == 0)
BRow1[i][j] = B[i][0];
else
BRow1[i][j] = A[i][j];
printMatrix(BRow1, 3, 3);
int BRow2[3][3];
printf("BRow2: ");
for(int i = 0; i < 3; i++)
for(int j = 0; j < 3; j++)
if(i == 1)
BRow2[i][j] = B[i][0];
else
BRow2[i][j] = A[i][j];
printMatrix(BRow2, 3, 3);
int BRow3[3][3];
printf("BRow3: ");
for(int i = 0; i < 3; i++)
for(int j = 0; j < 3; j++)
if(i == 2)
BRow3[i][j] = B[i][0];
else
BRow3[i][j] = A[i][j];
printMatrix(BRow3, 3, 3);
}

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