Question: I'm writing a c++ program to produce 2 random 4x4 matrix and (a) transpose the 2 matrix (b) multiply the two matrix. But the end

I'm writing a c++ program to produce 2 random 4x4 matrix and (a) transpose the 2 matrix (b) multiply the two matrix. But the end result of the multiplication is only showing one line. What did i do wrong?

#include #include #include #include using namespace std;

int main() { {

int A[4][4], B[4][4], trans_matrixA[4][4],trans_matrixB[4][4],result[4][4], rows, cols, i, j,k,sum; srand (time(NULL)); cout << "Array A is: " << endl; for (int i=0; i<4; i++) { cout<

for (int i=0; i<4; i++)

{ for (int j=0; j<4; j++)

{ cout << trans_matrixA[i][j] << "\t"; } cout << endl; }

cout << "Array B is: " << endl; for (i=0; i<4; i++) { for(j=0; j<4; j++) { B[i][j] = rand() % 11; cout << "\t" << B[i][j]; } cout << endl; } for (int i=0; i<4; i++) { for (int j=0; j<4; j++) { trans_matrixB[j][i]=B[i][j]; } } cout << "Transpose of the B Matrix: " << endl;

for (int i=0; i<4; i++)

{ for (int j=0; j<4; j++)

{ cout << trans_matrixB[i][j] << "\t"; } cout << endl; }

for(i=0; i<4; i++) { for(j=0; j<4; j++) { sum=0; for(k=0; k<4; k++) { sum = sum + trans_matrixA[i][k] * trans_matrixB[k][j]; } result[i][j] = sum; } }

// Displaying the multiplication of two matrix. cout << "Multiplication Matrix: " << endl; for(i=0; i<4; i++) { for(j=0; j<4; j++) { cout << result[i][j] << " "; cout << endl;

} cout << endl; system("pause"); return 0; }

} }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!