Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intranet And Web Databases For Dummies

Authors: Paul Litwin

1st Edition

0764502212, 9780764502217

More Books

Students also viewed these Databases questions